IonicWind Software

Aurora Compiler => 2D Graphics => Topic started by: SMartin on January 26, 2007, 11:34:37 PM

Title: C2DSprite Load workaround
Post by: SMartin on January 26, 2007, 11:34:37 PM
I decided to port over a Minesweeper clone I recently wrote from Emergence Basic to Aurora as a way of getting my feet wet in Aurora.
I subclassed the C2DScreen (called it TTWin) with the idea of doing all of the loading of sprites and drawing from inside the TTWin class, but I kept crashing the program when I called the Load method for the C2DSprite objects.
They need a pointer to a C2DScreen for the Load Method. I got around this by adding a member to the TTWin class that is a C2DScreen pointer and having the Global Sub main() pass the TTWin class what amounts to a pointer to itself (I even named the pointer 'Self') and delaying any initializations in the TTWin class until after the 'Self' pointer had gotten passed.
It works and now I'm just porting over the procedures from Emergence to Aurora, but I can't help thinking that I'm not doing this (drawing from within the C2DSceen TTWin class) in the recommended way.

Any help?...suggestions?

Thanks in advance,
Steve Martin.
Title: Re: C2DSprite Load workaround
Post by: Ionic Wind Support Team on January 26, 2007, 11:39:47 PM
When you are in a member function of a class the 'this' keyword is a pointer to the instance of that class.

TTWin::LoadAll()
{
     mysprite.Load(this,....
}

Since TTWin is derived from C2DScreen then the 'this' pointer is valid for any function that expects a pointer to a C2DScreen.

Paul.
Title: Re: C2DSprite Load workaround
Post by: SMartin on January 27, 2007, 01:38:31 AM
Hmmmm.....then I must have been doing something else wrong.
I started out by using 'this' in the C2DSprite Load method and that was crashing.
I'll go back over my code and see if I can find out were I went wrong.

Thanks Paul.
Title: Re: C2DSprite Load workaround
Post by: SMartin on January 27, 2007, 01:57:58 AM
OK, I found it. The OnPaint event is one of the places that calls the method that draws the sprites.
No doubt it's getting called before the class had a chance to get things going.
I set a variable that stops the OnPaint event from calling the drawing method too soon and all is well.

Thanks again,
Steve