Swift SpriteKit - 防止 sprite 节点 angular 旋转
Swift SpriteKit - Prevent sprite node from angular rotation
我试图阻止我的精灵旋转。我看过其他一些 Whosebug 答案,但没有任何帮助。当我将我的精灵移动到另一个节点或物理边界的一侧时,它会旋转它。
这是我在初始化精灵时尝试过的:
let texture = SKTexture(imageNamed:character.image)
let size = CGSize(width: character.width, height: character.height)
player = playerNode
player.name = "player"
player.physicsBody?.isDynamic = true
player.physicsBody?.allowsRotation = false
player.physicsBody?.angularVelocity = 1
player.texture = texture
player.position = CGPoint(x:0, y:0)
player.size = size
// Physics
player.physicsBody?.categoryBitMask = BodyType.player.rawValue
player.physicsBody?.contactTestBitMask = BodyType.dot.rawValue
player.physicsBody?.collisionBitMask = 0
player.physicsBody = SKPhysicsBody(texture: texture, size: size)
player.physicsBody?.linearDamping = 1
player.physicsBody?.angularDamping = 1
你的 player
实际上没有物理体,直到你到达 'physics' 部分的这一行:
player.physicsBody = SKPhysicsBody(texture: texture, size: size)
所以所有这些用于设置物理体属性的行都没有做任何事情:
player.physicsBody?.isDynamic = true
player.physicsBody?.allowsRotation = false
player.physicsBody?.angularVelocity = 1
// Physics
player.physicsBody?.categoryBitMask = BodyType.player.rawValue
player.physicsBody?.contactTestBitMask = BodyType.dot.rawValue
player.physicsBody?.collisionBitMask = 0
将物理体的创建移到 'physics' 部分的顶部,然后是所有物理体的 属性 赋值。
我试图阻止我的精灵旋转。我看过其他一些 Whosebug 答案,但没有任何帮助。当我将我的精灵移动到另一个节点或物理边界的一侧时,它会旋转它。
这是我在初始化精灵时尝试过的:
let texture = SKTexture(imageNamed:character.image)
let size = CGSize(width: character.width, height: character.height)
player = playerNode
player.name = "player"
player.physicsBody?.isDynamic = true
player.physicsBody?.allowsRotation = false
player.physicsBody?.angularVelocity = 1
player.texture = texture
player.position = CGPoint(x:0, y:0)
player.size = size
// Physics
player.physicsBody?.categoryBitMask = BodyType.player.rawValue
player.physicsBody?.contactTestBitMask = BodyType.dot.rawValue
player.physicsBody?.collisionBitMask = 0
player.physicsBody = SKPhysicsBody(texture: texture, size: size)
player.physicsBody?.linearDamping = 1
player.physicsBody?.angularDamping = 1
你的 player
实际上没有物理体,直到你到达 'physics' 部分的这一行:
player.physicsBody = SKPhysicsBody(texture: texture, size: size)
所以所有这些用于设置物理体属性的行都没有做任何事情:
player.physicsBody?.isDynamic = true
player.physicsBody?.allowsRotation = false
player.physicsBody?.angularVelocity = 1
// Physics
player.physicsBody?.categoryBitMask = BodyType.player.rawValue
player.physicsBody?.contactTestBitMask = BodyType.dot.rawValue
player.physicsBody?.collisionBitMask = 0
将物理体的创建移到 'physics' 部分的顶部,然后是所有物理体的 属性 赋值。