swift を使用した SpriteKit の発射体に関する簡単な質問です。手裏剣をスムーズに発射したい「モンスター」の次のコードがありますが、今のところ、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)
])
))
ありがとう