gpt4 book ai didi

ios - SKAction.removeFromParent 不要用 SKAction.repeatActionForever 删除 Sprite

转载 作者:可可西里 更新时间:2023-11-01 00:59:22 31 4
gpt4 key购买 nike

方法 .removeFromParent() 不会移除 Sprite 。怎么了?

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”不会消失

最佳答案

因为 actionRemove 永远不会被调用。

启动时:

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

依次运行 myShotAction SKAction,完成后运行 actionRemove。但是,如果第一个 SKAction 是一个永不结束的 Action (SKAction.repeatActionForever),则永远不会调用 actionRemove

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

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com