返回到相同条件下的上一个场景
Returning To Previous Scene In Same Condition
我有 GamePlayScene,它在结束时删除所有节点并显示分数和重新启动的选项。我在该场景上还有一个按钮,可将您带到另一个场景以显示可升级的项目。我想制作一个功能,在 "upgrade items" 场景上添加一个后退按钮,让我 returns 回到结束的 GamePlay 场景。我现在拥有的代码 returns 让我回到 GamePlay 场景,但重新启动游戏而不是显示游戏结束文本。我试过在线搜索,但找不到好的解决方案。我的代码:
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];
}
}
您可以将 SKNode
用作 "fake" SKScene
,然后使用 SKAction
对其进行动画处理(显示或隐藏)。
我有 GamePlayScene,它在结束时删除所有节点并显示分数和重新启动的选项。我在该场景上还有一个按钮,可将您带到另一个场景以显示可升级的项目。我想制作一个功能,在 "upgrade items" 场景上添加一个后退按钮,让我 returns 回到结束的 GamePlay 场景。我现在拥有的代码 returns 让我回到 GamePlay 场景,但重新启动游戏而不是显示游戏结束文本。我试过在线搜索,但找不到好的解决方案。我的代码:
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];
}
}
您可以将 SKNode
用作 "fake" SKScene
,然后使用 SKAction
对其进行动画处理(显示或隐藏)。