3

我有 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;
}
4

1 回答 1

0

尝试改变这个

_spriteView = (SKView *)self.view;

_spriteView = (SKView *)self.targetScene;
于 2013-10-09T10:21:35.737 回答