Access variables from a number of sources
Posted
by mac_55
on Stack Overflow
See other posts from Stack Overflow
or by mac_55
Published on 2010-03-29T00:36:16Z
Indexed on
2010/03/29
0:43 UTC
Read the original article
Hit count: 344
I'm creating my first game, and I've currently set up a 'GameState' class, to store player health etc. inside. This class is currently instantiated from the AppDelegate as I need to access it from all over my game.
This is fine. For each class I'm working in, I can access the app delegate, and then find the GameState object... however, it seems very messy. I'm tempted to find a way (I'm still a newbie) to define the GameState instance as being some sort of global variable so that I can access it from all over with ease... but my little bit of reading on variable scope makes me uneasy about doing this, even if I knew how.
Any ideas of the best way to define and access this class? It'll be used for everything from player health, to items they've found, any personalisation etc.
Thanks!
© Stack Overflow or respective owner