Archived

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

Trouble creating an attack animation on a single keypress.

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

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 on other sites
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 on other sites
Yeah that''s exactly what the problem was...pretty obvious now that I think about it. Thanks for the help.

Fa||en_Ange| Productions

Share on other sites
Is your name Jeremy by any chance Fallen Angel?