Hi. I'm a
beginner in DarkGDK and C++. I'm also new to this forum.
Recently I have encountered a problem involving explosions. My game is a 2d vertical space shooter where the player ship (bottom) has to shoot enemy ships (top). Once a bullet touches the enemy ship, the bullet and the enemy ship are deleted.
I've made it so that before the other plane is defeated, it will show an explosion animation. But, as the explosion begins, the whole screen stops for around half a second. The explosion continues after, then ends and is deleted.
I've been wondering for hours on why there's a slight lag before the explosion, but I've come up with nothing. Does anyone know how to prevent this? If so, how?
Here's my code:
//---
int enemy::collision() // function
{
for(int i = 200; i < 250; i++) // enemies
{
for(int a = 100; a < 120; a++) // bullets
{
for(int b = 250; b < 260; b++) // explosions
{
if(dbSpriteCollision(a,i)) // if enemy collides with bullet
{
dbStopSound(3); // stops explosion sound
dbCreateAnimatedSprite(b,"Images//explosion sheet.png",3,4,11); // creates the animated sprite of the explosion
dbSprite(b,dbSpriteX(i) - 20,dbSpriteY(i) - 20,11); // makes the explosion appear
dbSetSpriteFrame(b,1); // sets the explosion frame to 1
dbDeleteSprite(a); // deletes bullet
dbDeleteSprite(i); // deletes enemy
dbPlaySound(3); // plays explosion sound
}
dbPlaySprite(b,1,12,40); // plays the explosion
if(dbSpriteFrame(b) == 12) // if explosion is at the last frame
dbDeleteSprite(b); // delete it
}
}
}
return(0); // return
}
//---
I can has noobish skills.