我正在编写一个游戏,其中我有一个角色跟随另一个角色,我想制作它,以便第二个角色在第一个角色跳跃后跳跃1或2秒。我怎么能做到这一点?
这是我应用冲动的方法:
覆盖func touchesBegan(touches:Set,withEvent event:UIEvent){ / *触摸开始时调用* /
for touch in (touches as! Set<UITouch>) {
let location = touch.locationInNode(self)
fish.physicsBody?.velocity = (CGVectorMake(0,0))
fisherman.physicsBody?.velocity = (CGVectorMake(0,0))
fish.physicsBody?.applyImpulse(CGVectorMake(0, 1000))
fisherman.physicsBody?.applyImpulse(CGVectorMake(0, 3000))
}
}
答案 0 :(得分:0)
由于您已经采取了以下措施,因此您只需将其与延迟操作链接即可。有一个类方法waitForDuration,允许您快速初始化此类Action。
这是一段代码,它会延迟并在之后施加冲动:
for touch in (touches as! Set<UITouch>) {
fish.physicsBody?.velocity = (CGVectorMake(0,0))
fisherman.physicsBody?.velocity = (CGVectorMake(0,0))
let delay = SKAction.waitForDuration(2.0)
let fishApplyImpulse = SKAction.applyImpulse(CGVectorMake(0, 1000),
duration sec: 0.0)
let fishActions = SKAction.sequence([delay, fishApplyImpulse])
let fishermanApplyImpulse = SKAction.applyImpulse(CGVectorMake(0, 3000),
duration sec: 0.0)
let fishermanActions = SKAction.sequence([delay, fishermanApplyImpulse])
fish.runAction(fishActions)
fisherman.runAction(fishermanActions)
}
代码使用从iOS 9开始提供applyImpulse的SKAction添加。