制作爆炸动画SKaction并删除 [英] Make explosion animation SKaction and remove
问题描述
当两个精灵节点发生碰撞时,我想为我的游戏制作动画.所以我创建了这个功能:
I want to make a animation to my game when two sprite nodes have a collision. So i create this function :
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)
}
此代码可以正常工作,但我不知道在SKAction sequence
animateExplosion完成后如何删除SpriteNode
爆炸".
This code works perfectly but I don't know how can I delete the SpriteNode
"Explosion" when my SKAction sequence
animateExplosion is finished.
感谢您的帮助:)对不起我的英语,我是法语;)
Thanks for helping :) And sorry for my english i'm french ;)
推荐答案
您实现了错误的方法.代替runAction:
,实现runAction:completion:
. completion
方法将在完成后称为!.这就是删除爆炸节点的地方.
You've implemented the wrong method. Instead of runAction:
, implement runAction:completion:
. The completion
method will be called on completion! So that is the place to remove the explosion node.
这篇关于制作爆炸动画SKaction并删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!