Sign in to follow this  
boehmz

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this