使用swift快速解决SpriteKit中的射弹问题。 我为我的“怪物”提供了以下代码,我想要顺利拍摄shuriken然而,它现在只是在随机点弹出,而不是像我的角色那样顺利地拍摄它,当我在touhcesBegan函数中编码时
以下是代码:
func monsterShoots() {
let monsterShuriken = SKSpriteNode(imageNamed: "projectile-1")
monsterShuriken.position = monster.position
addChild(monsterShuriken)
monster.position.y += CGFloat(arc4random_uniform(30)) - CGFloat(arc4random_uniform(30))
monsterShuriken.position.x -= CGFloat(arc4random_uniform(1000))
let actionMoveMonster = SKAction.moveTo(monsterShuriken.position, duration: 1.0)
let actionMoveDoneMonster = SKAction.removeFromParent()
monsterShuriken.runAction(SKAction.sequence([actionMoveMonster, actionMoveDoneMonster]))
}
我在didMoveToView中重复了以下操作:
runAction(SKAction.repeatActionForever(
SKAction.sequence([
SKAction.runBlock(monsterShoots),
SKAction.waitForDuration(1.0)
])
))
由于
答案 0 :(得分:0)
我认为你需要写下这个:
monster.position.y += CGFloat(arc4random_uniform(30)) - CGFloat(arc4random_uniform(30))
之前:
monsterShuriken.position = monster.position