我正试图防止我的精灵旋转。我看过其他一些StackOverflow答案,但没有任何帮助。当我将精灵移动到另一个节点或紧靠物理边界一侧时,它将旋转它。
这是我初始化精灵时尝试过的:
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
答案 0 :(得分:1)
在您进入“物理学”部分的这一行之前,您的player
实际上没有物理学实体:
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
将物理实体的创建移至“物理”部分的顶部,然后将其分配给所有物理实体。