Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol><span style="font-style: italic; color: green;">//==============================================================================

<span style="font-style: italic; color: green;">// ** RPG: Move Sprite

<span style="font-style: italic; color: green;">//------------------------------------------------------------------------------

<span style="font-style: italic; color: green;">// Usage: 

<span style="font-style: italic; color: green;">// Argument0 is for what object you plan on moving

<span style="font-style: italic; color: green;">// Argument1 is for the direction

<span style="font-style: italic; color: green;">// Argument2 is for how many steps the sprite will move.

<span style="font-style: italic; color: green;">//------------------------------------------------------------------------------

<span style="font-style: italic; color: green;">// Written by Rukiri of Team Sapphire

<span style="font-style: italic; color: green;">//==============================================================================

 

<span style="font-weight: bold; color: #000000;">if([url=http://www.zonamakers.com/gmlreference/instance_number.html]<span style="color: navy;">instance_number[/url](obj_move_sprite) == <span style="color: #cc66cc;">0) {

<span style="font-style: italic; color: green;">// choose the sprite you plan to move

<span style="font-weight: bold; color: #000000;">with (argument0) {

 

<span style="font-style: italic; color: green;">// get direction

<span style="font-weight: bold; color: #000000;">direction = argument1; <span style="font-style: italic; color: green;">// use to change the sprites facing.

 

<span style="font-style: italic; color: green;">// 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.

globalvar sprite_steps;

sprite_steps = argument2;

 

<span style="font-style: italic; color: green;">// call object_move sprite to handle the movement. 

[url=http://www.zonamakers.com/gmlreference/instance_create.html]<span style="color: navy;">instance_create[/url](<span style="font-weight: bold; color: #000000;">x,<span style="font-weight: bold; color: #000000;">y,obj_move_sprite);   

}

}

// obj_move_sprite

Code:
<div class="gml" id="{CB}" style="font-family: monospace;"><ol>  <span style="font-weight: bold; color: #000000;">if tiles_moved > sprite_steps

  {

    moving=<span style="color: #cc66cc;">1;

    player_move_timer +=<span style="color: #cc66cc;">1;

    <span style="font-weight: bold; color: #000000;">if player_move_timer >= <span style="color: #cc66cc;">9

    {

      sprite_steps +=<span style="color: #cc66cc;">1;

      player_move_timer = <span style="color: #cc66cc;">0;

    }

    [url=http://www.zonamakers.com/gmlreference/motion_set.html]<span style="color: navy;">motion_set[/url](<span style="color: #cc66cc;">270, movesteps);

  }

<span style="font-weight: bold; color: #000000;">if tiles_moved == sprite_steps

{

  sprite_steps = <span style="color: #cc66cc;">0;

  [url=http://www.zonamakers.com/gmlreference/instance_destroy.html]<span style="color: navy;">instance_destroy[/url]();

}
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top