在相同条件下返回上一场景

时间:2015-08-05 01:11:43

标签: ios objective-c sprite-kit skspritenode skscene

我有GamePlayScene,结束时删除所有节点并显示分数和重启选项。我在该场景上还有一个按钮,可以将您带到另一个场景以显示可升级的项目。我想创建一个函数,在“升级项目”场景中添加一个后退按钮,返回到已结束的GamePlay场景。我现在的代码现在将我返回到GamePlay场景,但重新启动游戏而不是显示Game Over文本。我尝试过在线搜索,但我无法找到一个好的解决方案。我的代码:

GamePlayScene.m

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
                ...
        else if (self.restart) {
                [[GameState sharedInstance] saveState];
                if ([node.name isEqualToString:@"UpgradesButton"]){
                    UpgradeShipScene *upgradeScene = [UpgradeShipScene sceneWithSize:(self.frame.size)];
                    SKTransition *transition = [SKTransition fadeWithDuration:0.5];
                    [self.view presentScene:upgradeScene transition:transition];
                }
                ...
    }

UpgradesScene.m
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInNode:self];
        SKNode *node = [self nodeAtPoint:location];
        if ([node.name isEqualToString:@"BackButton"]){
            for (SKNode *node in [self children]){
                [node removeFromParent];
            }
            GamePlayScene *scene = [GamePlayScene sceneWithSize:self.view.bounds.size];
            SKTransition *transition = [SKTransition fadeWithDuration:0.5];
            [self.view presentScene:scene transition:transition];
        }
}

1 个答案:

答案 0 :(得分:1)

您可以使用SKScene作为“假”SKAction,然后使用indexOf为其设置动画(显示或隐藏)。