Reputation: 134
I would like to reload my scene, after some event in the game. But I would like to keep parameter for level (to increase it). How would you do that? I am a beginner in iOS development. I am having an idea of having some global variable, but not sure if that is possible and that is the right way to go. Thanks!
Upvotes: 1
Views: 289
Reputation: 3606
There are several choices,a few are:
If you want to keep the level value for future use (e.g. if the player can load their game at a later date), I'd use core data. If you don't need to store it long-term, I'd use a property on the parent view controller:
YourViewController.h:
#import YourScene.h
...
@property int level;
YourViewController.m
...
//before you present the scene
yourScene.viewController = self;
...
YourScene.h
#import YourViewController.h
@property (nonatomic,weak) YourViewController *viewController;
YourScene.m
...
//store the level in the parent controller
_viewController.level = 1;
...
Upvotes: 1