GML how to stop on frame of sprite?

L

Lemon85

Guest
I'm trying to make something happen if the player hits enter during a certain frame of a sprite's animation. Depending on when they press enter, the sprite will then freeze on that frame. Stopping on different frames will cause different things to happen. Is there any way to write this out in the code?

(I can't seem to figure it out from other posts)
 
A

Andy

Guest
You could try something like this:
Code:
// Create
image_speed_previous = image_speed;

// Step
if (keyboard_check_pressed(vk_enter))
{
    image_speed_previous = image_speed; // Save image_speed (animation speed)
}
if (keyboard_check(vk_enter))
{
    image_speed = 0; // Stop animation
    switch(image_index)
    {
        case 0:
        // Run if image was stopped at frame (image_index) 0
        break;
        case 1:
        // Run if image was stopped at frame (image_index) 1
        break;
    }
}
if (keyboard_check_released(vk_enter))
{
    image_speed = image_speed_previous; // Restore animation speed
}
Code:
// Create
image_speed_previous = image_speed;

// Step
if (keyboard_check(vk_enter))
{
    image_speed_previous = image_speed; // Save image_speed (animation speed)
    image_speed = 0; // Stop animation
    switch(image_index)
    {
        case 0:
        // Run if image was stopped at frame (image_index) 0
        break;
        case 1:
        // Run if image was stopped at frame (image_index) 1
        break;
    }
}
else
{
    image_speed = image_speed_previous; // Restore animation speed
}
 
Last edited by a moderator:
Top