[SOLVED] Change sub-image in path

J

jana

Guest
You can change the sub-image of an object that's on a path, can't you? My code doesn't seem to be working.
I want to change the sub-image based on which direction the object is moving in the path --- up, down, left, right.

This is in the create event:
Code:
image_index = 1;
image_speed = 0;
This is in the step event. I tried it in both begin step and step:
Code:
var proper_image_index = -1;

if(xprevious < x)
{
    proper_image_index = 0;
    if (proper_image_index != image_index)
    {
        image_index = proper_image_index;
    }
}
else
{
    if(xprevious > x)
    {
        proper_image_index = 2;
        if (proper_image_index != image_index)
        {
            image_index = proper_image_index;
        }
    }
    else
    {
        if(yprevious < y)
        {
            proper_image_index = 3;
            if (proper_image_index != image_index)
            {
                image_index = proper_image_index;
            }
        }
        else
        {
            if(yprevious > y)
            {
                proper_image_index = 1;
                if (proper_image_index != image_index)
                {
                    image_index = proper_image_index;
                }
            }
        }
    }
}
The sub-image doesn't change when the object changes direction in the path.

Am I missing something?
 
What values do you get for xprevious / yprevious and x/y in the Step Event if you output them to console using show_debug_message()?
 
J

jana

Guest
Code:
x is 102.000
y is 288.000
xprevious is 102.000
yprevious is 288.000
What values do you get for xprevious / yprevious and x/y in the Step Event if you output them to console using show_debug_message()?
I get that the xprevious and yprevious are the same as x and y.
The object is moving left to right starting at 0, on a straight horozontal line, y = 288.
I put this code in the step above the other code:
Code:
if (x >= 100)
{
    show_debug_message("x is " + string_format(x,3,3));
    show_debug_message("y is " + string_format(y,3,3));
    show_debug_message("xprevious is " + string_format(xprevious,3,3));
    show_debug_message("yprevious is " + string_format(yprevious,3,3));
    game_end();
}
The output:

x is 102.000
y is 288.000
xprevious is 102.000
yprevious is 288.000

I don't see how they could be the same.
 
J

jana

Guest
Got it figured out. I put the code in end step. So, the way I was doing it before, x and y hadn't been changed yet. Thanks for showing me show_debug_message. I didn't know I could do that. Now, I have to find that list of the order of actions in a step. I know I saw that somewhere ....
 
Top