I would recommend animating the frame very differently from how you want to
do it. I’d do this:
struct animate {
int sx, sy; // Start position
int x, y; //Position to get to/if the animation is done
int tx, ty; // Translated coordinates of the surface
Uint32 ms; // Time it should take to finish this animation
}
You tell the logo to get to a certain coordinate in a certain amount of
milliseconds (keep it independent of the frames…frame dependency is a very
bad idea)
Here how I would do it:
animate animation[5]; // 5 Step animation
animation[0].x = x; animation[0].y = y; animation[0].done = 0;
animation[0].ms = 500;
animation[0].tx = 0; animation[0].ty = 0;
// … for all animations
int doAnimation( animate *animations, int num, int *step, SDL_Surface
*surface, float framerate ) {
// calculate magnitude for x and y
float mx = 0.0f, my = 0.0f;
float dist = sqrt( (animations[*step].sx+animations[*step].x)^2 -
(animations[*step].sy+animations[*step].y)^2 ); // For some reason, I think
my distance formula is off - I haven’t had to use it in a while, so just
double check it…
mx = (animations[*step].tx - animations[*step].x) / dist;
my = (animations[*step].ty - animations[*step].y) / dist;
float distperframe = (framerate / 1000);
animations[*step].tx += mx * distperframe;
animations[*step].ty += my * distperframe;
// Blit here…
if( ( animations[*step].tx == animations[*step].x ) && (
animations[*step].ty == animations[*step].y ) ) {
*step++; if( *step >= num ) *step -= num;
return 0;
}
return 1;
}
I haven’t tested that code at all, so there is bound to be some problems
with it, but at least it’s a starting point.
Here is how you’d use it:
int step = 0;
float fr = 0.0f;
Uint32 startframe = 0;
while( 1 )
startframe = SDL_GetTicks();
if( ( doAnimation( &animation[0], 5, &step, surface, fr ) == 0 ) && (
steps == 5 ) ) {
break;
}
fr = ( (float)(SDL_GetTicks() - startframe) * 100 ) / 6; // or *1000)/60
…
}
I hope that is at least a start for you,
-AlexOn Thu, Jun 24, 2010 at 11:39 AM, Bob Pendleton wrote:
Ok, you have to problems, one is that you are animating the logo (at a
very high speed actually) and two that you are moving the logo.
So, first get the logo to animate in one place and then move it
around. BTW just because you have 16 frames for the logo do not make
the mistake of thinking you have to change the logo frame every time
the video frame updates. If you did that and the video is updating at
60 frames per second the logo would run through all its frames in
0.027 seconds, rather fast.
Take a look at:
http://linuxdevcenter.com/pub/a/linux/2003/05/15/sdl_anim.html
http://linuxdevcenter.com/pub/a/linux/2003/08/07/sdl_anim.html
http://linuxdevcenter.com/pub/a/linux/2003/10/23/sdl_anim.html
They’re a good introduction to how to do animation in SDL 1.2 and they
apply to SDL 1.3. They cover all the basics that you need to address
to do what you want done.
Bob Pendleton.
On Thu, Jun 24, 2010 at 2:28 AM, Smitha Rathnam <rathnam.smitha at gmail.com> wrote:
Hello All,
I need some help with writing code to animate a logo smoothly onto the
screen.
The logo can be drawn by using a function say, DrawLogo(frame, x,y),
where
’frame’ is the current frame of the logo, x and y are top left
co-ordinates
of the logo.
The logo moves through 16 frames and cycles back to frame 1 after frame
-
All its animations are complete within 16 frames.
It begins somewhere beyond the edges of the screen at frame 1.
My problem is: How to get the logo moving smoothly onto the screen from
beyond the edges?
We can make assumptions as to the resolution of the screen, the BPP
values
and the colour depth.
Please help.
Regards,
Smitha.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
–
±----------------------------------------------------------
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org