• Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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:

Instead of:

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement