GMS 2 I can't change image_speed when I change sprite_index

DavidRuiz

Member
Hello everybody, I'm trying to change my sprite_index, but when I do that I realized that the image_index is the same that the last time I used. How can I do to set the image_speed? "image_speed" doesn't work by the way. Thank you very much for your help!


// vertical movement
if frog_jump = true
{
ySpeed = - jumpPower;
frog_jump = false;
}

if(ySpeed>0)
{
sprite_index = spr_frog_jumping;
image_index = 1; // I CHANGE IMAGE_INDEX HERE
}
else
{
sprite_index = spr_frog_jumping;
image_index = 0; // AND HERE
}


ySpeed += weight;

if !place_meeting(x,y+ySpeed,obj_Block)
{
y += ySpeed;
}
else
{
move_contact_solid(point_direction(x,y,x,y+ySpeed),maxFallSpeed);
ySpeed = 0;
sprite_index = spr_frog_idle; // BUT WHEN I'M TRYING TO USE THIS SPRITE, THE SPRITE DOESN'T CHANGE IT'S IMAGE
image_speed = 4; IT'S SEEMS THIS IS NOT WORKING
}
 

MaxLos

Member
Yeah if your using Studio 1 or older your image speed is a multiplier of your room speed. The image speed in your code is 4, so if your game is running at 60 fps your sprite will have an image speed of 4 * 60, not 4 frames, which I'm assuming you want. For that just divide 4 or whatever speed you want by 60
 
Well, unless I'm mistaken, isn't the fact that you are directly setting image_index to an integer going to prevent the sprite from cycling through it's frames with it's normal image_speed? If image_index is set to 1 every frame, then it'll never be anything but 1, regardless of the image_speed.
 

DavidRuiz

Member
Does placing image_speed each time you change the sprite do anything? Cause your script only calls it one time.
Thanks for your answer but I tried putting "image_speed" out of the "if" statement but it doesn`t work. The think is that it works when I comment the first two "image_index", so I don`t think it`s about the "Image_speed" is called once.

What version of game maker is this?

Your image speed should be one or lower typically.
Thanks for your answer. I´m using GameMakerStudio 2.0. the last version exactly v2.2.5.378 and yes you`re right the correct code must be "image_speed = 1". I`ve changed it and I got sure that the sprite has 4 frames per second. But it doesn`t work
neither. The think is that it works when I comment the first two "image_index", but I need them for the first part of the animation.

Yeah if your using Studio 1 or older your image speed is a multiplier of your room speed. The image speed in your code is 4, so if your game is running at 60 fps your sprite will have an image speed of 4 * 60, not 4 frames, which I'm assuming you want. For that just divide 4 or whatever speed you want by 60
Thanks for your answer. You`re right, the correct code is "image_speed = 1". I`ve changed it and I got sure that the sprite has 4 frames per second. But it doesn`t work neither. The think is that it works when I comment the first two "image_index", but I need them for the first part of the animation.

pdt: hahaha for the spoiler XD

Well, unless I'm mistaken, isn't the fact that you are directly setting image_index to an integer going to prevent the sprite from cycling through it's frames with it's normal image_speed? If image_index is set to 1 every frame, then it'll never be anything but 1, regardless of the image_speed.
Thanks for your answer. Yes I think the problem is around here. When I comment the first two "image_index", the "image_speed = 1" works, but I need them for the first part of the animation. How can I set the image speed to normal after setting a image_index? This is the new code:


// vertical movement
if frog_jump = true
{
ySpeed = - jumpPower;
frog_jump = false;
}

if(ySpeed>0)
{
sprite_index = spr_frog_jumping;
// image_index = 1; --------- when I comment this
}
else
{
sprite_index = spr_frog_jumping;
// image_index = 0; ----------- and this,
}

ySpeed += weight;

if !place_meeting(x,y+ySpeed,obj_Block)
{
y += ySpeed;
}
else
{
move_contact_solid(point_direction(x,y,x,y+ySpeed),maxFallSpeed);
ySpeed = 0;
sprite_index = spr_frog_idle;
image_speed = 1; -------------- this works. But I need the commented lines for the complete animation.
}
 
Last edited by a moderator:

TheouAegis

Member
move_contact_solid(-90*sign(ySpeed),ySpeed);


if(ySpeed>0)
{
sprite_index = spr_frog_jumping;
image_index = 1;
}
else if ySpeed<0
{
sprite_index = spr_frog_jumping;
image_index = 0;
}

You probably don't need to worry about image_speed at all.

if ySpeed > weight {
sprite_index = spr_frog_idle;
image_index = 0;
}

^Use that in your collision code to prevent sprite locking just from standing on solid ground.
 
Last edited:
Top