# What can you put in Initialize() ?

## 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628326
• Total Posts
2982086

• 22
• 9
• 9
• 13
• 11