PDA

View Full Version : Anmation 2 at a time with a back ground



Ian_micheal
May 26th, 2004, 22:09
Posted this on my forum and dcemulation.com Not every one vists all those sites can you help a guy out on a simple type problem!

I have been trying to get Say 5 frames of anmation on to a back ground blitting while moving an object. Ive found the moving object slows it down because both are running from the main loop.

Any one got, an example, of running 2 anmation, at the same time. With a back ground behind, it and moving an object selector bar in the menu with out slowing down every thing else.


I was thinking if i had these anmations on a thread, they could run with out being effected by the other's. Allways a problem i have with games as well.

I could write up a fast example of it if needed. Not advanced just a problem that bugs me. Since you guys are so help-full i thought i ask and learn some thing I need to go forward on a project.

Infact here's a fast example from bit's and bobs.



#include <stdio.h>
#include <stdlib.h>
#include <kos.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <dc/maple.h>
#include <dc/maple/controller.h>
#include <mp3/sndmp3.h>

long bitrateold,bitratenew;

/* romdisk */
extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);
int main(int argc, char *argv[]) {
Uint32 flags = SDL_SWSURFACE|SDL_FULLSCREEN;
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_ShowCursor(SDL_DISABLE);
return -1;
}




SDL_Surface * screen;
SDL_Surface * title;
SDL_Surface * title2;
SDL_Surface * title3;
SDL_Surface * title4;
SDL_Surface * title5;
SDL_Surface * title6;
SDL_Surface * title7;
SDL_Surface * title8;
SDL_Surface * control;

SDL_Rect rect1;
SDL_Rect rect2;
SDL_Rect rect3;
int menu_sel = 0;
int ch = 0;
// 2 3 4 5 6 7 8
//1,2,3,4,1,5,6,7 (for the full animation)
screen = SDL_SetVideoMode(640, 480, 16, flags);
title = IMG_Load("/rd/background.jpg");
title2 = IMG_Load("/rd/eyes/1.jpg");
title3 = IMG_Load("/rd/eyes/2.jpg");
title4 = IMG_Load("/rd/eyes/3.jpg");
title5 = IMG_Load("/rd/eyes/4.jpg");
title2 = IMG_Load("/rd/eyes/1.jpg");
title6 = IMG_Load("/rd/eyes/5.jpg");
title7 = IMG_Load("/rd/eyes/6.jpg");
title8 = IMG_Load("/rd/eyes/7.jpg");




/* Put the Title screen up*/
SDL_BlitSurface(title, NULL, screen, NULL);




mp3_init();
timer_spin_sleep(100);
mp3_start("/rd/blah.mp3",1);

void inv_items(void)
{
rect2.y = 40;
rect2.x = 69;
rect2.h = 10;
rect2.w = 10;
SDL_BlitSurface(control, NULL, screen, &rect2);
SDL_Flip(screen);

}
//1,2,3,4,1,5,6,7 (for the full animation)
// 2 3 4 5 6 7 8
static void draw_screen1( void )
{

rect3.y = 152;
rect3.x = 94;
rect3.h = 10;
rect3.w = 10;

SDL_BlitSurface(title2, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title3, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title4, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title5, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title2, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title6, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title7, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);
SDL_BlitSurface(title8, NULL, screen, &rect3);
SDL_Flip(screen);
SDL_Delay (10);

}

// The lime we last toggled the anmation_1
int last_time = 0;

// Current state of the anmation_1
int anmation_1 = 0;

cont_cond_t cond;
while(1) {
int currentTime = SDL_GetTicks();
// And now draw the anmation
if(anmation_1)
draw_screen1( ); //
// If it's been more than half a second, toggle the image
if(last_time + 500 < currentTime)
{
last_time = currentTime;
anmation_1 = 1 - anmation_1;
draw_screen1( );
SDL_BlitSurface(title, NULL, screen, NULL);
SDL_Flip(screen);
cont_get_cond(maple_first_controller(), &cond);
if (cond.rtrig > 0) {
mp3_stop();
mp3_shutdown();
SDL_Quit();
return 0;
}
if (cond.ltrig > 0) {
inv_items();

}
}
}


If i add a menu to the while loop and keep drawing the background and try to blit the anmation it slows to a crawl i need better structor.