December 04, 2020, 03:55:06 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


C2DSprite Load workaround

Started by SMartin, January 26, 2007, 11:34:37 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SMartin

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

SMartin

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.

SMartin

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