views:

9

answers:

1

Hello, i was wondering how could i display 'player' sprite from Player.cs class. So far everything was happening in Program.cs file, witch had 'device' for rendering. Now i want to do same but using different classes. Do i need to create device for each class to render stuff thats happening within them, or i need to somehow access the device inside Program.cs file?

Thank you.

A: 

You would start by create the device in Program.cs, then if there is another class that will need to render via that device you would pass a reference to the device in that other class's constructor. It would store it in a private field, so it could use it whenever it needs to.

But this may be unnecessary: if you have a central Render method, you would probably be looping through various sprite objects and asking them to render themselves, by calling each object's own Render method. So you may as well pass them the device reference at that point, rather than making each object know the device it is attached to.

Daniel Earwicker