I just wanted to let everyone know that I had found the solution to my problem.First off the main problem was I was trying to do too much in one function.I had to break it up into smaller functions in order to make it work.I included the code just in case someone else might have this same problem down the road.
The Collision Function- in this one I basically created the animated sprite.And set the frame of the animation to one.
void collision()
{
for(int i =5; i <9; i++)
{
if(dbSpriteCollision(3,i))
{
enemyDestroyed = 1; //we want our explosion to happpen just before the plane is deleted
dbCreateAnimatedSprite(50,"explosion.png",4,4,50); //Animated Sprite for our explosion
dbSetSpriteFrame(50,1);
dbSetSpritePriority(50,1);
dbSprite(50,dbSpriteX(i), dbSpriteY(i),50);
dbDeleteSprite(3); //delete bullet
dbHideSprite(i); // delete the enemy plane
dbPlaySound(3); //Let's hear the explosion
score+= 100; //increase score by 100
//reposition code went here
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i ); //reposition enemy plane at top of screen
dbShowSprite(i);
dbScaleSprite(i,50); //make them half the original image size
//updateScore();
return;
}
}
for(int j = 10; j < 15; j++)
{
if(dbSpriteCollision(j,2)) //If the enemy bullets collide with the player's plane
{
dbDeleteSprite(j); //delete the enemy bullet
dbDeleteSprite(2); // delete the player's plane
dbPlaySound(3); //play explosion
}
}
The Explosion Function- In this function I had it look for the explosion sprite.If it saw the explosion sprite its job is to finish the animation
void Explosion()
{
if(dbSpriteExist(50)==1)
{
dbPlaySprite(50,1,16,100); //play explosion sprite
}
if(dbSpriteFrame(50)== 16) //if we have no more frames for the explosion
{
dbDeleteSprite(50); //delete the explosion
}
}
It was such a small seed... I needed to find out what was growing inside. And there was only one way to find out. So I decided to raise it.