This is just an example so I can't post my code. I haven't figured it out yet.
I've got a class that builds my game world. It calls other classes to do so. It all works fine. Now I'm working on other class for objects (like NPCs and such) in the world. I want them to access some of the worlds objects. The only way I know how to have object2 use object1's variables or objects is to send object1 to object2.
for example:
class WorldTime{ public WorldTime(gameTime gameTime){//this takes the game time and turns it in to world time}}class TheWorld{ WorldTime theTime = new WorldTime(gameTime); //huge class that generates the world //using theTime to do stuff like shadows //or whatever its just an example so I'm winging it}
Okay so I have the world now. I need some people in it, but they need to know what time it is. The only way I know how to access the world time is to send the world to that person.
class Person{ //variables TheWorld myWorld; //constructor public Person (TheWorld myWorld) { this.myWorld = myWorld; } public string myWatch() { return TheWorld.theTime.toString(); }}
Now does each person create a "world" for them self's or does it just point to the world. I read an article sometime ago, that said there is 2 ways to do this; one way points to that object, and another way copies it. One way you need to add something to tell it what your doing. I don't want 100 people with 100 copies of the world running around.
I forgot the article's name and I have no clue what this is called, so google isn't much help.
Can anyone help.
[Edited by - Gravy on December 3, 2010 6:38:14 PM]