how to deal with attacking animation?

Started by
14 comments, last by ISDCaptain01 9 years, 9 months ago

Well i found this algorithm, ill try it tonight:

bool hold_animation;
double hold_animation_delay;
double time_elapsed;

if (hold_animation) {
time_elapsed += delta_time;
if (time_elapsed > hold_animation_delay) {
hold_animation = false;
++frame;
}
else {
// do nothing, don't advance frame
}
}
else {
++frame;// animation_time += delta_time;
}
Advertisement
I'd highly recommend you remove all the different animation code, and centralize the animation structure/code logic to one area where you define it. as you stand now, your animation code looks to be all over the place, and as you can see it's beginning to screw you in that department.

basically, animations should run kindof independent to your input logic.

an example of that would be something like:


   object->processInput();
   object->UpdateAnimation();
all your framecount/framedelay/current frame stuff should be updated solely from inside UpdateAnimation. it's kindof ok to arbitrarily set your current frame from other parts of your gameplay logic(and truthfully this should be more of setting what animation you want to play, not the exact frame to play on). but you should not be arbitrarily controlling the actual animation updating from these other components.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Heck Yeah, I got it to work:


void Link::doAttack()
{
	if(canAttack)
	{
		attackanimcount++;
		if(attackanimcount > attackanimdelay)
		{
			canAttack = false;
			attackanimcount = 0;
		}
		else
		{
			linkSprite.curframe = 5;
		}
	}
	/*else
	{
	}*/
}

got it to work even better, awesome. heres the code if anyone wants to see:


void Link::doAttack()
{

	if(canAttack)
	{
		attackanimcount++;
		if(attackanimcount > attackanimdelay)
		{
			part1++;
			attackanimcount = 0;

			if(part1 > 1)
			{
				canAttack = false;
				attackanimcount = 0;
				part1 = 0;
			}
		}
		else
		{
			if(part1 == 0)
				linkSprite.curframe = 4;
			else if(part1 == 1)
				linkSprite.curframe = 5;
		}
	}
}

got it to work even better, awesome. heres the code if anyone wants to see:


void Link::doAttack()
{

	if(canAttack)
	{
		attackanimcount++;
		if(attackanimcount > attackanimdelay)
		{
			part1++;
			attackanimcount = 0;

			if(part1 > 1)
			{
				canAttack = false;
				attackanimcount = 0;
				part1 = 0;
			}
		}
		else
		{
			if(part1 == 0)
				linkSprite.curframe = 4;
			else if(part1 == 1)
				linkSprite.curframe = 5;
		}
	}
}

Glad to hear, but, again, be aware, this will only work if your game logic update is called at a specific rate. I don't really understand why you wouldn't use time to determine when to change frames, or allow attacking, rather than some unscientific frame count value.

But, if you're happy with it, good to hear :)

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

I did some testing and ran my game at 120fps and everything speeded up accordingly. I will experiment with what you said but for now i needed this quick and easy solution

This topic is closed to new replies.

Advertisement