Quick Question about animation

Simple Again, to animate using SDL, When you load your images load them
into an array, something like ths pseudo code

SDL_Surface * FootFrames[2];

 FootFrames[1]  = LoadIMG("FootImage1")
 FootFrames[2]  = LoadIMG("FootImage2")
 int       footAnim=0;

on your key events

if key pressed
footAnim++;

on your draw bitmaps part

SDL_BlitSurface(FootFrames[footAnim&1], NULL, Screen, NULL);

the important part here is that your footAnim just keeps incrementing but
the footAnim&1 is a bit wise AND, giving you only 0 or 1.

I hope this helps

Trish

PS please dont anyone say i have missed my error checks :stuck_out_tongue:

On 3/8/07, Patricia Curtis <patricia.curtis at gmail.com> wrote:

Thanks,

I’ll give this a try so basically all its doing is loading the 2
images in an array so when I call the key events I tell the array to
do an infinite array of 2 frames back and forth?

I’ll give it a try thanks again.(hope you answer that btw)^On 3/7/07, Patricia Curtis <patricia.curtis at gmail.com> wrote:

On 3/8/07, Patricia Curtis <patricia.curtis at gmail.com> wrote:

Simple Again, to animate using SDL, When you load your images load them
into an array, something like ths pseudo code

SDL_Surface * FootFrames[2];

 FootFrames[1]  = LoadIMG("FootImage1")
 FootFrames[2]  = LoadIMG("FootImage2")
 int       footAnim=0;

on your key events

if key pressed
footAnim++;

on your draw bitmaps part

SDL_BlitSurface(FootFrames[footAnim&1], NULL, Screen,
NULL);

the important part here is that your footAnim just keeps incrementing but
the footAnim&1 is a bit wise AND, giving you only 0 or 1.

I hope this helps

Trish

PS please dont anyone say i have missed my error checks :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Join phpdiscovery.com Now!

I’ll give this a try so basically all its doing is loading the 2
images in an array so when I call the key events I tell the array to
do an infinite array of 2 frames back and forth

Yeah just load the images into an array of 2 then when you blit cycle
through the array using the bit wise mask on the AnimationFrameCounter,
obviously this is only for a very simple two frame animation but Bit wising
will save you loads of If / switch statments , BTW i where ever i can i use
numbers that can be bit wised as a simple and will save loads of time and
checking.

&1 = 0-1 (2 Frames)
&3 = 0-3 (4 Frames)
&7 = 0-7 .(8 Frames) …and so on.

Trish x

Yea but for a third party that reads the code, its not obvious what that does.
I prefer long if-statements for the sake of readability. Most of that long
code gets optimized away by the compiler anyway.
So at least one should do proper commenting (imho).

Patricia Curtis schrieb:> >>I’ll give this a try so basically all its doing is loading the 2

images in an array so when I call the key events I tell the array to
do an infinite array of 2 frames back and forth

Yeah just load the images into an array of 2 then when you blit cycle
through the array using the bit wise mask on the AnimationFrameCounter,
obviously this is only for a very simple two frame animation but Bit
wising will save you loads of If / switch statments , BTW i where ever i
can i use numbers that can be bit wised as a simple and will save loads
of time and checking.

&1 = 0-1 (2 Frames)
&3 = 0-3 (4 Frames)
&7 = 0-7 .(8 Frames) …and so on.

Trish x



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Jessica