当两个精灵节点发生碰撞时,我想为我的游戏制作动画。所以我创建了这个函数:
func contactEntreMeteorites(Meteorites : SKSpriteNode , Meteorites2 : SKSpriteNode){
Meteorites.removeFromParent()
Meteorites2.removeFromParent()
let ExplosionTexture1 = SKTexture(imageNamed: "Explosion1.png")
let ExplosionTexture2 = SKTexture(imageNamed: "Explosion2.png")
let ExplosionTexture3 = SKTexture(imageNamed: "Explosion3.png")
let ExplosionTexture4 = SKTexture(imageNamed: "Explosion4.png")
let ExplosionTexture5 = SKTexture(imageNamed: "Explosion5.png")
let ExplosionTexture6 = SKTexture(imageNamed: "Explosion6.png")
let ExplosionTexture7 = SKTexture(imageNamed: "Explosion7.png")
let ExplosionTexture8 = SKTexture(imageNamed: "Explosion8.png")
let ExplosionTexture9 = SKTexture(imageNamed: "Explosion9.png")
let ExplosionTexture10 = SKTexture(imageNamed: "Explosion10.png")
let ExplosionTexture11 = SKTexture(imageNamed: "Explosion11.png")
let ExplosionTexture12 = SKTexture(imageNamed: "Explosion12.png")
let animateExplosion = SKAction.sequence([
SKAction.waitForDuration(0, withRange: 0),
SKAction.animateWithTextures([ExplosionTexture1,ExplosionTexture2,ExplosionTexture3,ExplosionTexture4,ExplosionTexture5,ExplosionTexture6,ExplosionTexture7,ExplosionTexture8,ExplosionTexture9,ExplosionTexture10,ExplosionTexture11,ExplosionTexture12 ], timePerFrame: 0.1)
])
Explosion = SKSpriteNode(texture: ExplosionTexture1)
Explosion.position = CGPointMake(Meteorites.position.x, Meteorites.position.y)
Explosion.runAction(animateExplosion)
self.addChild(Explosion)
}
此代码完美无缺,但我不知道如何在SpriteNode
animateExplosion完成时删除SKAction sequence
“Explosion”。
感谢您的帮助:)对不起我的英语我是法国人;)
答案 0 :(得分:3)
您实施了错误的方法。而不是runAction:
,实施runAction:completion:
。 completion
方法在完成时将被称为!这是删除爆炸节点的地方。
答案 1 :(得分:0)
所以这就是解决方案:
Explosion = SKSpriteNode(texture: ExplosionTexture1)
Explosion.position = CGPointMake(Meteorites.position.x, Meteorites.position.y)
self.addChild(Explosion)
Explosion.runAction(animateExplosion, completion : {self.Explosion.removeFromParent()})