Accessing the game window properties from within an object?
I'm working on a simple 2D game (Asteroids clone) where objects are flying into and off the screen. The player shoots at these as they pass through the screen. Blah, blah blah...
What I need is for these 'targets' to recognize when they have left the game window and I need the factory that creates them to know the size of the window so it can put them in at random off the screen, point then towards the screen, then send them on their way.
My question is: Is there a way to access the game window properties from within an object without passing the window into the constructor of those objects?
[605 byte] By [
Keldog] at [2007-12-24]
Jim Perry wrote: |
| The info in this thread answers your question, I believe. |
|
The services wasn't directly the answer, but it did point me towards one answer. You have to call the .getService() from a game object. That being, you have to have the game object accessable and therefore passed into the object (please correct me if I'm missing something). SpaceWars does this very thing. The constructor of 'Ship' takes a game object.
I guess this isn't that bad or even that cumbersome. Just wanted to know if there was a more efficient way.