Hi friends, I stuck here for a long time, please help, thanks!
there are two Viewcontrollers. On the first viewcontroller, named StartPageVC, there are 4 buttons. After pressing one of the 4 buttons, my App performs a segue to the secondviewcontroller to load one of the 4 levels respectively.
this secondviewcontroller contains a button to return to first viewcontroller and a Gamescene named MyScene. if the user passes the current level, it moves the gameLayer ( a SKNode ) downward out of the screen and shows up a Game over Panel. ( If the user clicks on the Game over Panel, the game starts with next new level.) We call it is status A to describe things clearly. After the user press on the return button, it goes back to the first Viewcontroller.
All works well so far, but when user presses one of the 4 buttons again, my App doesnot perform a segue to the secondviewcontroller to load one of the 4 levels respectively any more, instead, it returns the second viewcontroller with the same status A, as the status that before it returns from the second viewcontroller.
Actually I had used following method to try to dismiss the second viewcontroller before it returns to StartPageVC, but it still keeps returning to status A when
clicking one of the 4 buttons again, instead of loading corresponding Level, as the Game should be.
- (IBAction)BackToStartPageVCButton:(id)sender {
[self.backgroundMusic stop];
self.scene = nil;
[self.scene removeFromParent];
NSMutableArray *vcArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
[vcArray removeObjectAtIndex: 1];
self.navigationController.viewControllers = vcArray;
[self.navigationController popViewControllerAnimated:YES];
}
-------------------------- following are part of codes within StartPageVC.m
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
SKScene * scene = [startPageScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
scene.delegate = self;
NSURL *url = [[NSBundle mainBundle] URLForResource:@"song18" withExtension:@"mp3"];
self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
self.backgroundMusic.numberOfLoops = -1;
[self.backgroundMusic play];
[skView presentScene:scene];
}
self.startPageVC = [[self storyboard] instantiateViewControllerWithIdentifier:@"StartPageVC"];
self.secondViewController = [[self storyboard]
instantiateViewControllerWithIdentifier:@"secondViewController"];
self.goTOsecondVCSegue = [[GoTOsecondVCSegue alloc] initWithIdentifier:@"goTOsecondVC"
source:self
destination:self.secondViewController];
}
[self.goTOsecondVCSegue perform];
- (void)perform
{
StartPageVC *sourceViewController = self.sourceViewController;
secondViewController *destinationViewController = self.destinationViewController;
destinationViewController.view.backgroundColor = [UIColor clearColor];
destinationViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[sourceViewController.navigationController pushViewController:destinationViewController animated:YES];
}