• Advertisement
Sign in to follow this  

Sprites not completing animation.. Solved - credit to nomichi

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, Im using c++ and allegro.. I have a vector full of sprites. As they fall towards the bottom, Im trying to change the type and put into effect an animation before they disappear. Problem is, the animation isnt playing and they just disappear. Im sure the code is barbaric, but here is the relevant source I have.

struct drp
{
	float x, y;
	float xVel, yVel;
	int type;
	int frame;
	int dead;
	int delay;
	int tick;
};

BITMAP *raindrop_dissipate[5];
BITMAP *redbrick_dissipate[5];
BITMAP *rainbow_dissipate[5];
BITMAP *lightning_dissipate[5];
BITMAP *raindrop[3];
BITMAP *redbrick[3];
BITMAP *rainbow[3];
BITMAP *lightning[3];

raindrop[0] = load_bitmap("raindrop.bmp", NULL); 

//**********************************************************************
void new_drop(float x, float y, float xVel, float yVel, int type, int frame, int dead, int delay, int tick = 0)	
{
	drp b = {x, y, xVel, yVel, type, frame, dead, delay, tick};
	drops.push_back(b);
}



void process_drops()
{
	for(std::vector<drp>::iterator Current = drops.begin(); Current != drops.end();) // run through drop list
	{
		Current->tick++;
		if(Current->tick == Current->delay)
		{
			Current->tick = 0;
			Current->frame ++;
		}

		if(Current->dead != 1)
		{
			if (Current->y < 510) // near bottom of screen
			{
				Current->x += Current->xVel;
				Current->y += Current->yVel;
				if(Current->frame > 2)
					Current->frame = 0;
				Current++;
			}
			else if (Current->y >= 510)
			{
				Current->dead = 1;
			}
		}
		else if (Current->dead == 1)
		{
			// insert else code here to process drop that hit ground
			if(Current->type == 0)
			{
				Current->type = 4; //raindrop_dissipate
				Current->frame = 0;
				Current->delay = 100;
				raindrops_missed ++;
			}
			else if(Current->type == 1)
			{
				Current->type = 5; //rainbow_dissipate
				Current->frame = 0;
			}
			else if(Current->type == 2)
			{
				Current->type = 6; //brick_dissipate
				Current->frame = 0;
			}
			else if(Current->type == 3)
			{
				Current->type = 7; //lightning_dissipate
				Current->frame = 0;
			}

			if(Current->frame >= 5)
			{
				Current = drops.erase(Current);
			}
		}
	}
}





	for(std::vector<drp>::iterator Current = drops.begin(); Current != drops.end();)
	{
		switch(Current->type)
		{
			case 0:
				draw_sprite(buffer, raindrop[Current->frame], Current->x, Current->y);
				break;
			case 1:
				draw_sprite(buffer, rainbow[Current->frame], Current->x, Current->y);
				break;
			case 2:
				draw_sprite(buffer, redbrick[Current->frame], Current->x, Current->y);
				break;
			case 3:
				draw_sprite(buffer, lightning[Current->frame], Current->x, Current->y);
				break;
			case 4:
				draw_sprite(buffer, raindrop_dissipate[Current->frame], Current->x, Current->y);
				break;
			case 5:
				draw_sprite(buffer, rainbow_dissipate[Current->frame], Current->x, Current->y);
				break;
			case 6:
				draw_sprite(buffer, redbrick_dissipate[Current->frame], Current->x, Current->y);
				break;
			case 7:
				draw_sprite(buffer, lightning_dissipate[Current->frame], Current->x, Current->y);
				break;
		}

		Current++;
	}





In the process_drops() function, if a drop hits the 510 mark on the y, it should change its type to an alternate, and set itself to dead so it doesnt get processed in the first part of the function anymore. Then, it should continue to be processed displaying the animation for its 5 frames plus delay, then be erased. Problem is, I can put in an allegro_message(""); routine when it changes its type, and it does show that it changed the type, but at that point the sprite just disappears instead of playing out its animation. Anyone have any ideas where Im going wrong here? Other than barbaric code I keep changing and hacking? =) Im sure the error is somewhere in the process_drops function, but ill be if I cant find it.. [Edited by - cdxrd on May 31, 2006 10:28:58 PM]

Share this post


Link to post
Share on other sites
Advertisement
Its hard to tell :)

A few things I have had trouble with in the past is:
1. The size of each sprite (I don't see that in your code)
2. I don't know how big your bitmaps are but If you have more than one row of sprites that needs to be accounted for.

From what I can tell you only have two frames of animation is this right?

Share this post


Link to post
Share on other sites
The way it sits right now, each sprite is a separate file, most about 35x45. They display fine, and the first animations as they drop plays fine (which is only 3 frames). Its the section where I change the type, and change the number of frames of animation . This part doesnt animate at all.

Share this post


Link to post
Share on other sites
I glanced over it. Looks like Current is never incremented once it is dead. Maybe that is your problem? Your ticks and frames probably incrementing faster than it can display once it's stuck on a specific "Current" and then destroying it.

Share this post


Link to post
Share on other sites
I owe you nomichi! Thank you thank you thank you! You were right, and my logic in my mind was wrong, current wasnt getting incremented.. =) I stared at that and played around for several hours, and it just never occured to me..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement