Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

testgame

macrumors newbie
Original poster
Jun 9, 2010
21
0
Hello,

I m new to iPhone Platform.I want to make simple game.

In my game i need some data like (Score, levelnumber,etc) throughout game. How can i declare this variables. I know only one way. But i think it is not proper. Create one global.h file. add all global variables in this file & import global.h file when i want to use this data.

I heard about delegate & protocol.

Please tell me which is best way to transfer data between views & track global data throughout app.

Thanks in Advance.
 
Either put properties in your application delegate object which is easily available via the global singleton UIApplication or create your own singleton object that represents the game in progress. For one or two items of data I'd go the first way, more than that the second.
 
Another way would be to send notifications with pertinent userInfo when game data changes, and then objects can register to recieve notification that interest them. For example you could subclass a uiLabel which watches for gameScoreChange notifications, and changes it's text to the new score.
 
Another way would be to send notifications with pertinent userInfo when game data changes, and then objects can register to recieve notification that interest them. For example you could subclass a uiLabel which watches for gameScoreChange notifications, and changes it's text to the new score.


Thank u very much to both for replying.

This answers will really help me.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.