ignoring the standing frame

Started by BOYD1981, Mon 16/07/2007 07:58:56

Previous topic - Next topic

BOYD1981

i'm looking for a way to make the character to carry on using the last walking frame it used when it stops and then resume from that frame when it starts to walk again (or some way of delaying the character stopping until it has reached a certain frame), instead of instantly returning the the standing frame.
the distance between my character's legs can be quite long around half way through the cycle and instantly going from legs far apart to side by side in an instant looks a bit odd.
a feature like this could turn into a useful module.

Limey Lizard, Waste Wizard!
01101101011000010110010001100101001000000111100101101111011101010010000001101100011011110110111101101011

Scorpiorus

Quote from: BOYD1981 on Mon 16/07/2007 07:58:56
i'm looking for a way to make the character to carry on using the last walking frame it used when it stops and then resume from that frame when it starts to walk again

You can do this by repeatedly substituting a sprite of the character's standing frame with the current walking frame while it's moving, and also saving its current frame to start from later on moving again:

repeatedly_execute_always:
Save current walking frame and change standing frame's graphic.
Code: ags


int last_walking_frame = -1;


function repeatedly_execute_always() {

    if (player.Moving)
    {
        last_walking_frame = player.Frame;
        
        ViewFrame *standing_frame = Game.GetViewFrame( player.NormalView, player.Loop, 0 );
        ViewFrame *current_frame  = Game.GetViewFrame( player.NormalView, player.Loop, last_walking_frame );
        
        standing_frame.Graphic = current_frame.Graphic;
    }
}



on_mouse_click:
Resume walking from the last saved frame.
Code: ags

function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
    
    // After ProcessClick, check if we are in the Walkto mode and then change the frame:
    //------------------------------------------------------------------------------------
    if (mouse.Mode == eModeWalkto)
    {
        if (last_walking_frame != -1)
        {
            player.Frame = last_walking_frame;
        }
    }
    //------------------------------------------------------------------------------------

  }
  else {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
}


Note that I used "player" to reference the player's character. Let me know if you need the same for every other one too -- that would require setting up an array and iterating through all of them in a while loop.


Quote(or some way of delaying the character stopping until it has reached a certain frame)

That's also possible but a bit tricky, as its destination is always defined by a point you clicked over the screen. So you then need either to move it a little further or just play a stopping animation while it's already stand still.

A more complicated approach would be to dynamically fiddle with frame delays of a NormalView to try and sync character's moving with its walking animation.

SMF spam blocked by CleanTalk