Legacy GM help on moving sprite

E

EZTALES

Guest
hey yall,
i wrote this little bit of code but i need it for 7 sprites instead of only 3 in this case, i assume its a easy fix but i have no idea on how to do it any help is great!
Code:
Step Event
if keyboard_check_pressed(vk_right) and image_index != 2 then image_index += 1 //moves player right
if keyboard_check_pressed(vk_left) and image_index != 0 then image_index -= 1 //moves player left
 
Off the top of my head I think this will do it:

if keyboard_check_pressed(vk_left)
{
if image_index > 0
{image_index -= 1}
}

if keyboard_check_pressed(vk_right)
{
if image_index < (image_number - 1)
{image_index += 1;}
}

Image_number is the amount of frames the currently used sprite has, and Image_index starts at zero so the final frame is one less than image_number. If you find that you don't get the last frame then remove the - 1 from "image_number - 1"

I should ash though - you put "moves player left / right etc", but this will only cycle through the animation frames, and not physically move an object. Is that what you want?
 
E

EZTALES

Guest
Off the top of my head I think this will do it:

if keyboard_check_pressed(vk_left)
{
if image_index > 0
{image_index -= 1}
}

if keyboard_check_pressed(vk_right)
{
if image_index < (image_number - 1)
{image_index += 1;}
}

Image_number is the amount of frames the currently used sprite has, and Image_index starts at zero so the final frame is one less than image_number. If you find that you don't get the last frame then remove the - 1 from "image_number - 1"

I should ash though - you put "moves player left / right etc", but this will only cycle through the animation frames, and not physically move an object. Is that what you want?
yes, this is what im after, ill gie a try and get back to you, thanks!
 
E

EZTALES

Guest
Off the top of my head I think this will do it:

if keyboard_check_pressed(vk_left)
{
if image_index > 0
{image_index -= 1}
}

if keyboard_check_pressed(vk_right)
{
if image_index < (image_number - 1)
{image_index += 1;}
}

Image_number is the amount of frames the currently used sprite has, and Image_index starts at zero so the final frame is one less than image_number. If you find that you don't get the last frame then remove the - 1 from "image_number - 1"

I should ash though - you put "moves player left / right etc", but this will only cycle through the animation frames, and not physically move an object. Is that what you want?
this does work! the only thing left that I want is when you have made it to the final sprite, (sprite 7) loop back to the very first one. I only want this for the last sprite and not the first as well so you don't go backward. thanks!
 
Top