RPG: Move Sprite RPG Maker movement function

INFO
This little script was made for creating RPGs and making them much much easier to code, this way you do not have to time HOW long
a sprite should move with a grid.

If you're using pixel-movement change the timer in the object to 2, though 4X4 or 8X8 is good.
Chrono Trigger and the Mana games used these grids.

Usage
RPG:Move_Sprite(object,direction,# of tiles to move)

Facts:

The timer for the movement object is timed for a 8X8 grid(snes) so if you need to time for say 32X32 it should be no different in time.
But, each grid has a different time which it needs to be set at.

Please be advised that you'll need to code the actual move sprite object, I gave an example for moving south(down), it's the same process for each direction. Just use the switch function and carry out the motion sets accordingly.

- Rukiri

  1. //==============================================================================
  2. // ** RPG: Move Sprite
  3. //------------------------------------------------------------------------------
  4. // Usage:
  5. // Argument0 is for what object you plan on moving
  6. // Argument1 is for the direction
  7. // Argument2 is for how many steps the sprite will move.
  8. //------------------------------------------------------------------------------
  9. // Written by Rukiri of Team Sapphire
  10. //==============================================================================
  11.  
  12. if(instance_number(obj_move_sprite) == 0) {
  13. // choose the sprite you plan to move
  14. with (argument0) {
  15.  
  16. // get direction
  17. direction = argument1; // use to change the sprites facing.
  18.  
  19. // Sprite_Steps is used for counting, so a tile is 8X8 for example and you set it to 3, so you're mvoing 3X8 in the direction you choose.
  20. globalvar sprite_steps;
  21. sprite_steps = argument2;
  22.  
  23. // call object_move sprite to handle the movement.
  24. instance_create(x,y,obj_move_sprite);   
  25. }
  26. }
Expand to see the code.


// obj_move_sprite

  1.  if tiles_moved > sprite_steps
  2.   {
  3.     moving=1;
  4.     player_move_timer +=1;
  5.     if player_move_timer >= 9
  6.     {
  7.       sprite_steps +=1;
  8.       player_move_timer = 0;
  9.     }
  10.     motion_set(270, movesteps);
  11.   }
  12. if tiles_moved == sprite_steps
  13. {
  14.   sprite_steps = 0;
  15.   instance_destroy();
  16. }
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=71882