Sprite Kit在块中更改私有变量

时间:2014-12-18 02:13:53

标签: swift sprite-kit

我是sprite kit的新手,我试图完成最后一段代码。在离开游戏场景之前,我试图查看屏幕上是否还有更多特定类型的节点。 noMoreOrangesFlag是我放在swift文件顶部的私有变量。请让我知道如何实现这一目标。

var noMoreOrangesFlag = false;

/**
 * @Name: didEvaluateActions
 * @Description: This is part of the lifecycle of the app per frame.
 * @Parameters: None
 * @Returns: void
 * @Throws: No Excception
 */

override func didEvaluateActions() {
    if(gameOverFlag){
        // This is a private variable I need to change
        noMoreOrangesFlag = false;

        // This is where I'm trying to see if there are any oranges on the screen
        enumerateChildNodesWithName(orangeImageName) { node, _ in
            self.noMoreOrangesFlag = true;
        }

        if(!noMoreOrangesFlag){
            // THIS IS THE FINAL THING RAN. OFFICIAL GAME OVER

            NSLog("Machine");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

使用该方法实现我想要的目标

if(childNodeWithName(orangeImageName) == nil){
                // THIS IS THE FINAL THING RAN. OFFICIAL GAME OVER

                NSLog("Machine");
}