开发者

How can I access one ivar from multiple scenes in Cocos2D?

开发者 https://www.devze.com 2023-03-01 17:46 出处:网络
Thank You for taking a look at my question! In my 开发者_如何学Pythongame I have several scenes. I have an IntroScene, a HomeScene, and a PlayingScene. Now, if I need to create a variable int playerSt

Thank You for taking a look at my question! In my 开发者_如何学Pythongame I have several scenes. I have an IntroScene, a HomeScene, and a PlayingScene. Now, if I need to create a variable int playerStrength and I want it to start of as being 0, but it needs to be displayed in my HomeScene and the PlayingScene needs to have the ability to access it as well, how can I do this? Because the HomeScene needs to display this integer, and the PlayingScene needs to know what it is so it can effect the amount of damage the player does. (And the players class would also need to know what this variable has to be). I have been suffering from this for a very long time and would REALLY appreciate some help! Thank You!


Create a model class encapsulating this kind of info, alloc it in your app delegate and have all others get to it via [UIApplication sharedApplication].delegate. You can do key value observing on it for view controllers that need to know when values change - classic MVC architecture.


I recently wrote a tutorial on exactly these types of architectural issues: http://www.hollance.com/2011/04/making-your-classes-talk-to-each-other-part-1/

0

精彩评论

暂无评论...
验证码 换一张
取 消