Swift sprite套件中投射物的平滑过渡
只是一个关于SpriteKit中使用swift的投射物的快速问题。 我有我的“怪物”的以下代码,我想顺利地射出shuriken,但是,它现在只是在随机点出现,而不是像我在Touhcesbegin函数中编码时从我的角色那里顺利射出 代码如下:Swift sprite套件中投射物的平滑过渡,swift,sprite-kit,projectile,Swift,Sprite Kit,Projectile,只是一个关于SpriteKit中使用swift的投射物的快速问题。 我有我的“怪物”的以下代码,我想顺利地射出shuriken,但是,它现在只是在随机点出现,而不是像我在Touhcesbegin函数中编码时从我的角色那里顺利射出 代码如下: func monsterShoots() { let monsterShuriken = SKSpriteNode(imageNamed: "projectile-1") monsterShuriken.position = monster
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)
])
))
谢谢我想你需要写以下内容:
monster.position.y += CGFloat(arc4random_uniform(30)) - CGFloat(arc4random_uniform(30))
在此之前:
monsterShuriken.position = monster.position
如果看不到更多的代码,很难回答。但是看起来你是先设置怪物和它的shuriken位置,所以它们会猛拉到这些位置,然后你设置动作,但是当动作运行时,它们是毫无意义的,因为你之前设置了位置。可能是错的。只是猜测而已。有一段时间没有做精灵编码了。但是您应该显示更多的代码。