方法.removeFromParent()不会删除精灵。怎么了?

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

}

带有动画的精灵“myShot”不会消失

最佳答案

仅仅是因为actionRemove永远不会被调用。

启动时:

myShot.runAction (SKAction.sequence([myShotAction, actionRemove]))

依次运行myShotAction SKAction和完成后的actionRemove。但是,如果第一个SKAction是一个永无休止的动作(SKAction.repeatActionForever),则actionRemove将永远不会调用。

关于ios - SKAction.removeFromParent不要使用SKAction.repeatActionForever删除 Sprite ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37513830/

10-12 06:03