SashDing SashDing - 6 months ago 34
iOS Question

SKAction.removeFromParent do not remove a sprite with SKAction.repeatActionForever

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]))

}


sprite "myShot" with animation does not disappear

Answer

Madhouse. I replaced the action

 SKAction.repeatActionForever

per action

SKAction.repeatAction

and everything worked.