我有一个需要 SKPhysicsJointFixed.joint 的小游戏,并且一切正常,除了一个事实,即关节在 10 秒处于活动状态时会减慢精灵的速度,速度似乎是没有关节活动的精灵速度的一半。
我已经尝试过,恢复原状,密度甚至速度,但它们都起作用了。有人可以指导我正确的方向。我在这里找不到任何东西,或者谷歌似乎没有用。
带有 Shield 和 showPhysics = true 的宇宙飞船的图像:
func activateShield() {
let shield1 = SKTexture(imageNamed: "shield-1")
let shieldImages = [shield1, SKTexture(imageNamed: "shield-2"), SKTexture(imageNamed: "shield-3"), SKTexture(imageNamed: "shield-4"), SKTexture(imageNamed: "shield-5"), SKTexture(imageNamed: "shield-6")]
let animateShield = SKAction.animate(with: shieldImages, timePerFrame: 0.10)
let animateRepeatShield = SKAction.repeatForever(animateShield)
shield = SKSpriteNode(texture: shield1)
shield.name = "ShieldActive"
shield.setScale(2.5)
shield.position = player.position
shield.zPosition = 3
shield.physicsBody = SKPhysicsBody(rectangleOf: shield.size)
shield.physicsBody!.affectedByGravity = false
shield.physicsBody!.categoryBitMask = PhysicsCategories.ShieldActive
shield.physicsBody!.collisionBitMask = PhysicsCategories.Enemy
shield.physicsBody!.contactTestBitMask = PhysicsCategories.Enemy | PhysicsCategories.LifePu
shield.physicsBody!.isDynamic = true
shield.physicsBody!.density = 0
self.addChild(shield)
shield.run(animateRepeatShield)
let joint = SKPhysicsJointFixed.joint(withBodyA: player.physicsBody!, bodyB:shield.physicsBody!, anchor:player.position)
self.physicsWorld.add(joint)
//turns off the shield in between 5-10 seconds
shield.run(.wait(forDuration: 10, withRange: 0)) {
self.shield.removeFromParent()
}
}