What can you put in Initialize() ?

This topic is 3049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

This is probably a totally newb question that has an obvious answer. It seems that you can't initialize anything you need to use later on in the Initialize() method. For example, I create a rectangle in Initialize and then want to use that rectangle to draw a sprite in the Draw() method. This results in an error because it "doesn't exist in the current context."

Share on other sites
You could load models, fonts, create devices. Do some calculations, such as defining camera position, calculating building/tree collisions with terrain and etc

Share on other sites
You can initialize anything you want in the Initialize() method, however to use it outside of the method you need to declare the variable outside it.

IE:

Initialize(){Rectangle rect = new Rectangle(...);}

Use:
Rectangle rect;Initialize(){rect = new Rectangle(...);}

You will then be able to access rect in your draw method.

This is fairly basic stuff.