GML Making moving object change sprites depending on direction

Hello, everyone! I have a player object changing animated sprites depending on a "move_x" and a "move_y" variables, both set by pressing directional keys. Now I'm trying to make the player move automatically through a script, but even if the script works fine, I have no idea how to make the two "move" variables change depending on the direction the player is being moved. Thanks for any help!
 
The script is correct, and moves the objects to set destinations as intended. All I need is a way for the "move_x" and "move_y" of the player object to change depending on the directions the player object is being moved by the script.
 

woods

Member
not much to go on but here's the basic jist of it.... would be easier for people to help if they know how your player moves ;o)

Code:
if player is moving right
{
draw_sprite(spr_player_right, 1, x, y);
}

if player is moving left
{
draw_sprite(spr_player_left,1,x,y);
}

if player is no0t moving
{
drw_sprite(player_idle,1,x,y);
}
 
Thanks for the response! I use an enum to organize the sprites and they are controlled like this:

Code:
if (moveX < 0) direction_facing_ = dir.left;
else if (moveX > 0) direction_facing_ = dir.right;
else if (moveY < 0) direction_facing_ = dir.up;
else if (moveY > 0) direction_facing_ = dir.down;
else {
image_speed = 0;
image_index = 0;
}
While the script I'm using to control automatic movements is:

Code:
///@description move_character
///@arg object
///@arg x
///@arg y
///@arg relative?
///@arg spd

var obj = argument0, relative = argument3, spd = argument4;

if (x_destination == -1) {
    if(!relative){
        x_destination = argument1;
        y_destination = argument2;
    } else {
        x_destination = obj.x + argument1;
        y_destination = obj.y + argument2;
    }
    
}

var xx = x_destination;
var yy = y_destination;

with(obj) {
    if(point_distance(x,y, xx, yy) >= spd){
        var dir = point_direction(x, y, xx, yy);
        var ldirectionx = lengthdir_x(spd, dir);
        var ldirectiony = lengthdir_y(spd, dir);
    
        x += ldirectionx;
        y += ldirectiony;
    } else {
        x = xx;
        y = yy;
        
        with(other){
            x_destination = -1;
            y_destination = -1;
            end_action();
        }
    }
}
To make the player object change sprites I added this to the script:

Code:
obj.automove = true;
if obj.x > x_destination { obj.moveX = -1;}
else if obj.x < x_destination { obj.moveX = +1;}
else if obj.y > y_destination { obj.moveY = -1;}
else if obj.y < y_destination { obj.moveY = +1;}
But I'm wondering if there is a better, more direct way to check the direction the player object is being moved.

Cheers!
 
Top