`SKView *skView = (SKView *) self.view;
SKScene *scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:scene];`
所以 MyScene 是您在开始游戏时呈现的主页。在选择地图并在游戏中失败后,如果您按下按钮返回主页并直接返回游戏的地图部分 我点击的地图会随机加载到视图中。任何帮助都会很棒,我没有收到错误,因为它只是加载到视图中并启动游戏。
好的,这是主页场景中的代码,可将您发送到部分屏幕
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//Called when a touch begins
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
if([node.name isEqualToString:@"playButton"])
{
SKView *skView = (SKView *) self.view;
SKScene *scene = [SectionsScreen sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:scene];
}
}
然后,一旦您选择了第一部分,您将转换到视图控制器,其中所有地图都加载到其中。
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
node.xScale = 1;
node.yScale = 1;
for (SKSpriteNode *label in self.sectionNumAra)
{
if([[@"section" stringByAppendingString:label.name] isEqualToString:node.name])
{
label.xScale = 1;
label.yScale = 1;
}
}
if([node.name isEqualToString:@"section1"])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"closeScene" object:nil];
MainViewController *main = [[MainViewController alloc]init];
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: main animated: YES completion:nil];
}
这是过渡到那个。
选择地图过渡到此处的 skscene 后
SKView *skView = (SKView *) self.view;
SKScene *scene = nil;
//Continue to make if statements to open the correct map.
if([[GameData sharedGameData].mapChosen isEqualToString:@"FirstMap"])
{
scene = [FirstMap sceneWithSize:skView.bounds.size];
}
scene.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:scene];
到目前为止一切都很好......现在一旦“游戏结束警报弹出,如果您选择返回部分屏幕(这是一个场景),您可以回到那里。但是在点击一个部分后,您不允许进入。我将先前的地图或先前的视图控制器直接加载到该场景中。