`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];
到目前为止一切都很好......现在,如果你选择回到Sections Screen(这是一个场景),那么当游戏结束时会弹出警报,你可以回到那里。但点击一个部分后你就不允许进入。我将之前的地图或上一个视图控制器直接加载到该场景中。
答案 0 :(得分:0)
[[NSNotificationCenter defaultCenter] postNotificationName:@" closeScene"对象:无];
这就是问题所在。我只是在其他场景之上呈现场景。需要通过发布通知从层次结构中删除场景。问题解决了!