Animation is stuck for a bit too long in a fight scene

Started by Olleh19, Mon 26/10/2020 14:20:48

Previous topic - Next topic

Olleh19

I'm using player.Stopmoving(); that releases the frame eventually. But it's way too slow, and the players punch is stuck in the air for a second (just guessing).
Learnt that  from looking at the Keyboard Module, however it does something else too, that i can't really replicate as of yet.

Question: Which is I would like for the action button Z not to be held down, but triggered only when pushing it and released instantly after releasing the button.

How would i create such a function? This is what i use so far, it's too much code to paste here, but you  get the idea. Very basic!


IsButtonDown only works for mouse it seems..or i'm probably missing something obvious

Code: ags
if (IsKeyPressed(eKeyZ))
   
   
   
{
    
    
    
    
    

    if (cAxl.Loop==2 || cAxl.Loop==3 || cAxl.Loop==4 || cAxl.Loop==5) //RIGHT Hit

{
    


      cAxl.Animate (10, 0, eOnce, eNoBlock); 

      cAxl.SetIdleView(5, 0);                           //This is a idle view to the RIGHT, so after he punches, he stays at the same side.                            

      cAxl.Baseline=0;
}
  



Khris

Use on_key_press for that.

Regarding the idle view, it should contain a bunch one loop for each direction, that way it will use the proper loop automatically.

Olleh19

Quote from: Khris on Mon 26/10/2020 18:15:34
Use on_key_press for that.

Regarding the idle view, it should contain a bunch one loop for each direction, that way it will use the proper loop automatically.

I stand corrected as always. Thanks!

Olleh19

I'm unsure what to call in it tho.


I'm confused. It's the same result as before. The function do get called  i've checked that with the Display("");
So it must be something else to cancel his ongoing frame and go back to the position/idle he was in before the punch.

Should the Punch Attack be in another view then his basic moveset i mean (Left, Right, Down, Up)? Maybe that's what i'm doing wrong.

Code: ags
function on_key_press(eKeyCode keycode) 
{
  if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
  
  if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
  if (keycode == eKeyF9) RestartGame(); // F9
  if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
  if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
  if (keycode == eKeyZ) cAxl.StopMoving();
}


Khris

I meant to run the animation in on_key_press, not to stop it in there.

Also yes, put the animation in a separate view, then use LockView, Animate, UnlockView.

Olleh19

Quote from: Khris on Mon 26/10/2020 22:43:35
I meant to run the animation in on_key_press, not to stop it in there.

Also yes, put the animation in a separate view, then use LockView, Animate, UnlockView.

I think i misunderstood the logic completely. I thought "on_key_press" is when it's already been triggered by IsKeyPressed.

So when creating custom functions for action buttons in my own script. I should use On_Key_press and not Iskeypressed?

What's the prefered method?

Reason i ask is when the character hits another character. Sometimes (if holding the button, or pressing the button). It registers two or three hits instead of One, which is the intended behaviour.
I'm not sure On_key_press would actually solve that issue alone. I hope it will tho.

Khris

In general you use on_key_press to handle a single key press (like taking a screenshot, or a hotkey to switch to a different cursor mode).

Using IsKeyPressed(), which only makes sense in repeatedly_execute type functions, is usually used to handle the user holding down a button (like walking in a jump'n'run type game).

So the main question is how you want your game to behave. Is the user supposed to hold down the keys? If not, what do you want to happen if they do that?

Olleh19

Quote from: Khris on Mon 26/10/2020 23:45:29
In general you use on_key_press to handle a single key press (like taking a screenshot, or a hotkey to switch to a different cursor mode).

Using IsKeyPressed(), which only makes sense in repeatedly_execute type functions, is usually used to handle the user holding down a button (like walking in a jump'n'run type game).

So the main question is how you want your game to behave. Is the user supposed to hold down the keys? If not, what do you want to happen if they do that?

Ok! Thanks that cleared it up. Well, a lot of things is happening that is not very point & clicky, that's all i can say, right now :-D. It's a sidescroller "plattformer", i guess kind of attempt. And the character should NOT just go to "a normal idle view" simply cause there is no "down pose" or "up pose" in a sidescroller.  :) Maybe if i'm lucky i do not need to do the change to On_Key_press at all, changing the Punch to a single View made all the difference. Now the punch brings itself back which should in theory i suppose make it less keen to introduce "unwanted hits" unless ofc  holding down the button, which i guess could still be an alternative game play style. The story continues! (laugh)


Thanks as always for all the help!

SMF spam blocked by CleanTalk