Jump to content
  • Advertisement

Archived

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

Fallen_Angel

Trouble creating an attack animation on a single keypress.

This topic is 6085 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

Basically I'm creating a side-scrolling game (Golden Axe style) and am having trouble getting an attack animation to work with a single keypress. If I hold the attack button down everything seems to work fine, however simply pressing the button once will only show the next frame and not the whole animation. Any help would be appreciated. EDIT: Ignore the second half of the case statement (4 - 7), I'm only trying to get 0 - 3 working for now. Thanks.
    

void CObjectManager::attack(int index)
{
	int i;
	BOOL bCanAttack = FALSE; //Sufficient time has elapsed since last attack movement.

	CObject *sprite = pObjectList[index]; //Current object.

	int direction = sprite->nCurrentDirection; //Direction object is facing.

	if (Timer.elapsed(nLastAttack, nAttackTime))
		bCanAttack = TRUE;
	if (bCanAttack)
	{
		if (index == 0) //Main character.

		{
			switch (direction)
			{
				case 0:
				case 1:
				case 2:
				case 3:
					i = 0;
					while (i < 4)
					{
						if (Timer.elapsed(nLastMove, nMoveTime))
						{
							sprite->attack(0, 0);
							i++;
						}
					}
					break;
				case 4:
				case 5:
				case 6:
				case 7:
					sprite->attack(0, 1);
					break;
			}
		}
	}		
} //End attack(int index)


    
Fa||en_Ange| Productions
Edited by - Fallen_Angel on February 16, 2002 6:41:25 PM

Share this post


Link to post
Share on other sites
Advertisement
To me it seems like you call CObjectManager::attack() only if a key is pressed. You''ll have to call it every frame to get the animation to work. I''m not sure if I''m right, but the code you posted seems to be alright and that''s what came into my head. I hope that helps.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!