SpriteKit在复制节点时留了一个巨坑给开发者,需要开发者手动把复制节点的isPaused设置为false

根据When an overlay node with actions is copied there is currently a SpriteKit bug where the node’s isPaused property might be set to true提示,SpriteKit有一个Bug需要开发者自己来填。

SpriteNode节点在被copy()复制后,会自动被设置为暂停,也就是节点的所有Action全部不可用,如果需要使用node.run(SKAction.run{//code})

需要把复制后的节点isPaused设置为false

需要把复制后的节点isPaused设置为false

需要把复制后的节点isPaused设置为false

重要的事情说三遍 !!!

let overlayScene = SKScene(fileNamed: "ShoseScene")!
        let overlayShose = overlayScene.childNode(withName: "Overlay") as! SKSpriteNode
        let gameSceneOverlay = overlayShose.copy() as! SKSpriteNode
        overlayShose.removeFromParent() // 移除旧的
        /* 留意SpirteKit的巨坑
         * When an overlay node with actions is copied  there is currently a SpriteKit bug
         * where the node’s isPaused property might be set to true
         * 一定要记得设置为 false 或者所有gamesceneOverlay内的子节点的所有action都不起作用
         */
        gameSceneOverlay.isPaused = false;
        gameSceneOverlay.enumerateChildNodes(withName: "shose") { (node, _) in
            let sprite = node as! ShoseNodeClass
            sprite.newInstance(scene: self.scene!) // 加入物理体;
        }

使用的场景

  // 特效果汁
    func emitParticles(particleName: String, sprite: SKSpriteNode) {
       // isPaused =false 后,获得的sprite才可以运行.run,否则不起作用;
        sprite.run(SKAction.run({
            sprite.removeFromParent()
            print ("精灵节点内 hit shoses")
        }))
    }

更多Swfit游戏教学:http://www.iFIERO.com

posted @ 2018-08-04 13:19  布袋  阅读(161)  评论(0编辑  收藏  举报