我目前对我制作的游戏存在问题,我想询问是否有解决方案。基本上,我的游戏完全加载到主菜单没有任何问题,就像任何其他应用程序一样快,但是当我按下播放按钮,将你带到MainGameScene时,它需要大约3-4秒才会出现该场景。它仅在您第一次按下播放按钮时发生。所以,如果你死了,回到主菜单再次点击播放,它会立即加载。所以我的问题是,为什么加载MainGameScene需要几秒钟?编码时我错过了什么?它不是预加载? - (void)loadTextures {
我刚试过这个,但场景不会从加载屏幕转换到主菜单场景。有什么想法吗?
NSMutableArray *imageArray = [[NSMutableArray alloc] initWithObjects:@"obstacle.png","background.png","Ghost.png", nil];
[SKTexture preloadTextures:imageArray withCompletionHandler:^
{
SKTransition *reveal = [SKTransition fadeWithDuration:0.75];
MGLCreateMainMenuScene *scene = [[MGLCreateMainMenuScene alloc] initWithSize:self.view.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
[self.view presentScene:scene transition:reveal];
}];
}
答案 0 :(得分:0)
您的预加载代码不正确。请试试这个:
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
[imageArray addObject: [SKTexture textureWithImageNamed:@"obstacle.png"]];
[imageArray addObject: [SKTexture textureWithImageNamed:@"background.png"]];
[imageArray addObject: [SKTexture textureWithImageNamed:@"Ghost.png"]];
[SKTexture preloadTextures:imageArray withCompletionHandler:^
{
SKTransition *reveal = [SKTransition fadeWithDuration:0.75];
MGLCreateMainMenuScene *scene = [[MGLCreateMainMenuScene alloc] initWithSize:self.view.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
[self.view presentScene:scene transition:reveal];
}];