Reputation: 163
The The method .removeFromParent() does not remove the sprite. What's wrong?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
guard touches.first != nil else {
return
}
let myShot = SKSpriteNode()
let myShotAnimation = SKAction.repeatActionForever(SKAction.animateWithTextures(myShotTexture, timePerFrame: 0.01))
myShot.size = CGSizeMake(200, 200)
myShot.anchorPoint = CGPoint(x: 0.5, y: 0.5)
myShot.zPosition = 0
sprite!.addChild(myShot)
let myShotAction = SKAction.group([SKAction.scaleBy(0.1, duration: 0.5), myShotAnimation])
let actionRemove = SKAction.removeFromParent()
myShot.runAction (SKAction.sequence([myShotAction, actionRemove]))
}
The sprite "myShot" with animation does not disappear
Upvotes: 2
Views: 590
Reputation: 163
Madhouse. I replaced the action
SKAction.repeatActionForever
per action
SKAction.repeatAction
and everything worked.
Upvotes: 0
Reputation: 35382
Simply because actionRemove
will never be called.
When you launch:
myShot.runAction (SKAction.sequence([myShotAction, actionRemove]))
sequentially running the myShotAction
SKAction and , when it's finished, the actionRemove
. But if the first SKAction is an action thats never ends (SKAction.repeatActionForever), the actionRemove
will never called.
Upvotes: 3