我有 2 个视图控制器。在第一个视图控制器中,有游戏的介绍和徽标,在第二个视图控制器中,它加载了场景。我通过单击按钮从我的第一个视图控制器移动到第二个视图控制器。但它变成了错误。我的代码在第二个视图控制器中是:
@interface MPAPViewSceneController()
@property (nonatomic, retain) MPAPMyScene *targetScene;
@property SKView *spriteView;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
_spriteView = (SKView *)self.view;
_spriteView.showsFPS = YES;
_spriteView.showsNodeCount = YES;
_spriteView.showsDrawCount = YES;
}
-(void)viewWillAppear:(BOOL)animated {
self.targetScene = [[MPAPMyScene alloc] initWithSize:CGSizeMake(768.0f, 1024.0f)];
[_spriteView presentScene:self.targetScene];
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:YES];
self.targetScene = nil;
}
在场景中,我编写了下面给出的代码:
@interface MPAPMyScene()
@property (nonatomic) BOOL contentCreated;
@end
@implementation MPAPMyScene
-(void)didMoveToView:(SKView *)view {
if (self.contentCreated == NO) {
[self createSceneContents];
self.contentCreated = YES;
}
}
-(void)willMoveFromView:(SKView *)view {
[self removeAllChildren];
}
-(void)createSceneContents {
self.backgroundColor = [UIColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
}