如何在精灵套件中设置类别遮罩?
How to set category mask in sprite kit?
let dart = SKSpriteNode(imageNamed: "Dart")
dart.physicsBody?.isDynamic = true
dart.physicsBody?.categoryBitMask = 3
dart.physicsBody?.collisionBitMask = 2
当我打印飞镖类别时,它会屏蔽它 returns 零。我已经通过场景编辑器设置了其他精灵类别蒙版,它们工作正常。感谢您的帮助。
你还没有实际制作物理体
dart.physicsBody = SKPhysicsBody(...)
dart.physicsBody?.isDynamic = true
// etc.
...取决于您想要的物理体类型(圆形、矩形、多边形等)。请参阅此处的示例:
https://developer.apple.com/documentation/spritekit/sknode/getting_started_with_physics_bodies
let dart = SKSpriteNode(imageNamed: "Dart")
dart.physicsBody?.isDynamic = true
dart.physicsBody?.categoryBitMask = 3
dart.physicsBody?.collisionBitMask = 2
当我打印飞镖类别时,它会屏蔽它 returns 零。我已经通过场景编辑器设置了其他精灵类别蒙版,它们工作正常。感谢您的帮助。
你还没有实际制作物理体
dart.physicsBody = SKPhysicsBody(...)
dart.physicsBody?.isDynamic = true
// etc.
...取决于您想要的物理体类型(圆形、矩形、多边形等)。请参阅此处的示例: https://developer.apple.com/documentation/spritekit/sknode/getting_started_with_physics_bodies