在我的didBeginContact函数中,我检测到龙与子弹之间的碰撞。
在didBeginContact里面我给龙分配了两个动作。第一个是移动到屏幕的左侧,第二个动作是将他发送到屏幕上。
问题在于下一行代码。当我调用函数resetBullet时,当子弹击中龙时会引起轻微的延迟。如果我删除了resetBullet函数,当龙和子弹接触时,滞后就会消失。
这是didBeginContact和resetBullet
func didBeginContact(contact: SKPhysicsContact) {
let firstBody = contact.bodyA
let secondBody = contact.bodyB
if firstBody.categoryBitMask == bulletCategory && secondBody.categoryBitMask == dragonCategory || firstBody.categoryBitMask == dragonCategory && secondBody.categoryBitMask == bulletCategory{
dragonNode.runAction(SKAction.moveTo(loadRandSpawnLeft(), duration: 0.0))
dragonNode.runAction(SKAction.moveTo(CGPointMake(self.frame.size.width, dragonNode.position.y), duration: 5))
//resetBullet()
view?.userInteractionEnabled = true
}
}
func resetBullet(){
let resetBulletAction = SKAction.moveTo(CGPointMake(self.frame.size.width * 0.5385, self.frame.size.height * 0.175), duration: 0.0)
bulletNode.runAction(resetBulletAction)
bulletNode.zRotation = 0
view?.userInteractionEnabled = true
}