ios - How to reference the current Viewcontroller from a Sprite Kit Scene -
I have difficulty finding the answer to this question, I think it is not difficult.
How can I define methods and properties defined on a visual controller from SKScene?
And build on it: How can you refer to the ViewController reference from SKScene that was loaded inside of another SKScene?
Avoid Optionally you use in in SKScene context from
UIViewController Should, because it breaks MVC pattern.
NSNotificationCenter for
UIViewController about high scores:
ViewController :
- (zero) awakeFromNib {[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (reportScore) Name: @ "ReportScore" object: zero]; } - (Zero) Report: Type: (NSNotification *) Information {NSDictionary * userInfo = [Information user information]; NSNumber * score = (NSNumber *) [userInfo objectForKey: @ "scores"]; // Do your stuff with GameCenter ....} - (Zero) dealloc {// If you do not remove yourself as a supervisor, try the notification object // Disconnected object to // object object And will continue. . [[NSNotificationCenter defaultCenter] Delete the Observer: Self]; }
SKScene :
- (zero) game more often {NSDictionary * userInfo = [Object with NSDictionary dictionary: [NSNumber numberAd : To self Score: @ "score"]; [[NSNotificationCenter defaultCenter] postNotificationName: @ "ReportScore" Item: Self User Info: userInfo]; }
Comments
Post a Comment