Archived

This topic is now archived and is closed to further replies.

Dospro

Problem with time

Recommended Posts

Hi, i have a little problem with time. Is there any way to make an explosion last more than 5 miliseconds???? I tried to use SDL_Delay but that functions pauses the entire game and i only want to make the explosion last more. Is there a good way???

Share this post


Link to post
Share on other sites
A couple of ways come to mind:

1. Used time based sprite animation (see Cone3D''s sprite tutrial)

2. Use a time based particle system.

In both cases, update the animation frame or particle position after a predetermined period has passed.

HTH

Share this post


Link to post
Share on other sites
or just keep telling the explosion what time it is and let it update itself according to it''s own rules as fast as possible

explosion->Update( time );

("Let''s see... it''s 5037 and i was born on 4788 so i should be on frame 2 by now. [blit frame 2]")

Share this post


Link to post
Share on other sites
Yes, i got it.

The hard thing will be implement this with my previous code.
Well thats the thing dont you think?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Gee. Soundz like you need some sort of "Explosion" helper class, to help the explosion animation sprite do its thing. Is your explosion generated randomly?, or do you have a fixed length animation? Either way, you gonna wanna play at a particular frame rate for a certain perion of time. Like, maybe 10 ms instead of 5. Or maybe a lengthy 2 second explosion. I would use the Sprite''s Tick callback method to accomplish this. As you probably already know, this normally gets invoked X number of times a second to allow sprite to change position, frame etc.
Maybe the base sprite interface now as a new method called "Explode", with FPS, and total time? How do u currently apply an explosion operation to a sprite?

Share this post


Link to post
Share on other sites
Well. For my common sprites i use structures.(i hate classes)
But for explosion well i''ve just got the 4 images and each one is loaded in a surface. Then when the collicion occurs they are blitted in the position of the destroyed object. first it is blited the fist imgen, then the second and so on.

I made a function that goes in the main loop which it is evaluated all the time. And if a collicion occurs then the evaluation of this function change and starts blitting the explosions but with certain time, and when it finishes with the last iamge the evaluation of the function returns to its previous way.

I really didnt saw the difference, because i only see the first image blitted.

But well more help with this will be use full.

The function i used is:


void dibujarexplosion(int tiempo, int x, int y)
{
if(exp==1)//If it is 1, there was a collicion.
{
sact=SDL_GetTicks();
if(sact{
pintarimagen(explosion[1], pantalla_sdl, x, y, explosion[1]->w, explosion[1]->h, 0, 0);
if(sact{
pintarimagen(explosion[2], pantalla_sdl, x, y, explosion[2]->w, explosion[2]->h, 0, 0);
if(sact{
pintarimagen(explosion[3], pantalla_sdl, x, y, explosion[3]->w, explosion[3]->h, 0, 0);
if(sact{
exp=0;//when the last image was painted then it stops painting
}
}
}
}
else
{
pintarimagen(explosion[0], pantalla_sdl, x, y, explosion[0]->w, explosion[0]->h, 0, 0);
}
}
}


This goes in the main loop.



Share this post


Link to post
Share on other sites