PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How do you animate objects using GD ?

I need help in displaying/animating objects using GD or the basic idea. I implemented it but is it not smooth. I want to see others code in animation.

For example: A static winking smiley face or an on/off switch with 4 or more images.

Note : This doesn't involve movements from 1 location to others.

If someone can post their Class, Algo or Struct, I would appreciate it. Thanks.
GD as GapiDraw? animate objects as animated sprites?

just load a bitmap with all the sprite animation frames and copy each sprite cell to the screen

Code:

// Draw doors on top of tiles (hide them)
mDoorRect.top = 0;
mDoorRect.bottom = mDoorHeight;
mDoorRect.left = mDoorIndex * (mDoorWidth+1);
mDoorRect.right = mDoorIndex * (mDoorWidth+1) + (mDoorWidth);
for( i=0; i<NUM_DOORS; i++ )
{
backbuffer.BltFast( mDoorPosition[i].x, mDoorPosition[i].y, mDoorAnim->GetSurface(), &mDoorRect, GDBLTFAST_KEYSRC, NULL);
}


this will draw NUM_DOORS on the screen. mDoorIndex indicates which frame from the animation it should copy (in my case theres 10 frames for the animation), so just increment that var and u will have an animation.
hope it helps
Thanks Vic, I'll try your algo :-)
if you are wanting smooth animation you have to take into account actual time passing & the frame rate so you need to know the number of frames your sprite has, how it's moving ( up down left right etc ) how far you are moving it each time (a No. of pixels, how fast you are flipping between frames etc. The sprite's motion depends on these factors. For smooth animation which is independant of how fast the PPC is running you need to animate using an amount of elapsed time & not just how fast your game loop is running.
thats true. still u do that with the door example var (mDoorIndex).
just take framerate or time in account when changing it. play with it until you're sastified :>
Thanks connan and vic. I got the idea now :-)
vic wrote:
GD as GapiDraw? animate objects as animated sprites?

just load a bitmap with all the sprite animation frames and copy each sprite cell to the screen

Code:

// Draw doors on top of tiles (hide them)
mDoorRect.top = 0;
mDoorRect.bottom = mDoorHeight;
mDoorRect.left = mDoorIndex * (mDoorWidth+1);
mDoorRect.right = mDoorIndex * (mDoorWidth+1) + (mDoorWidth);
for( i=0; i<NUM_DOORS; i++ )
{
backbuffer.BltFast( mDoorPosition[i].x, mDoorPosition[i].y, mDoorAnim->GetSurface(), &mDoorRect, GDBLTFAST_KEYSRC, NULL);
}


this will draw NUM_DOORS on the screen. mDoorIndex indicates which frame from the animation it should copy (in my case theres 10 frames for the animation), so just increment that var and u will have an animation.
hope it helps



Sorry i'm noobs in pocket pc dev.
But which kind of language is it ? is it c ?
which software will i need to compile this ? :roll:
The above example will work in either C or C++. Regardless you will need eMbedded Visual C++ to compile it for the Pocket PC (and now pgcc). It is available from Microsoft's Pocket PC Developer section.

JJB