3

I have 2 viewcontroller. In the first viewcontroller, there is the introduction and logo of the game and in the second viewcontroller it loads the skscene. And I travel from my first viewcontroller to second viewcontroller with a button click. But it becones error. My code is in the second viewcontroller is:

@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;
}

And in the scene I have written the code given below:

@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;
}
Banshi
  • 1,335
  • 2
  • 13
  • 21

1 Answers1

0

Try changing this

_spriteView = (SKView *)self.view;

to

_spriteView = (SKView *)self.targetScene;
DogCoffee
  • 19,820
  • 10
  • 87
  • 120