GML image speed issue (beginner) SOLVED

R

RCarnival

Guest
Hello, I've very new to GMS, I'm currently working on learning the different coding and used the same code I used from a tutorial learning how to make the character's sprite speed look good but when I used it in a new game with little to know differences the sprite speed is going way too fast... I made sure the sprite speeds were all the same 15 frames per second and have image speed set to 1... not sure what I'm messing up..

Obj_Hero

Create:
hsp = 0;
vsp = 0;
grv = 0.5;
walksp = 6;
Step:
//Movement
key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);

//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp +grv;

if (place_meeting(x,y+1,Obj_Ground)) && (key_jump){
vsp = -10
}

//Horizontal Collision
if (place_meeting(x+hsp,y,Obj_Ground)) {
while (!place_meeting (x+sign(hsp),y,Obj_Ground)) {
x = x + sign(hsp);
}
hsp = 0;

}
x = x + hsp;

//Vertical Collision

if (place_meeting(x,y+vsp,Obj_Ground)) {
while (!place_meeting(x,y+sign(vsp),Obj_Ground)) {
y=y+sign(vsp);
}
vsp = 0;
}
y = y+vsp;

//Animation
if (!place_meeting(x,y+1,Obj_Ground)) {
sprite_index = Spr_HeroAir;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0) {
sprite_index = Spr_Hero;
}
else {
sprite_index = Spr_HeroWalk
}
}

if (hsp!=0) image_xscale = sign(hsp);

If you can see what I'm doing wrong it would be greatly appreciated!!
 
R

RCarnival

Guest
try image_speed = 0.25 in the create event, maybe you want 0.5, or whatever, try the first one
I tried this and it completely stopped the animation if it was anything lower than 1... :\
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
I made sure the sprite speeds were all the same 15 frames per second and have image speed set to 1... not sure what I'm messing up..
First of all, "sprite speeds" are for preview only. That setting in the sprite editor doesn't affect anything at run time.

An image_speed of 1 means 1 animation frame per game frame. The final speed of the animation in real time depends on your game's frame rate. At 60 frames per second, that's 60 animation frames per second. A sprite with 6 subimages would display its entire animation 10 times within a second with that frame rate and animation speed.


Edit: As corrected below by @IndianaBones, this applies for GM:S 1.x and earlier only. You learn something new every day... shame on me!

If setting image_speed to something less than 1 stops the animation completely, something else is interfering with it. Ensure that your animation speed is only affected by the corresponding object, isolate it and experiment around with different values while closely watching its image_index variable to find clues about what might be wrong.
 
Last edited:
@RCarnival What version of GMS are you using?

What @TsukaYuriko said applies for 1.4.

However in GMS 2, image_speed is actually a multiplier of the speed that you set in the sprite editor.

So if you set the frames per second to 15 and the image_speed to 1, final speed in game is 15 * 1 = 15

image_speed of 0.5 in GMS 2 would result in 15 * 0.5 = 7.5 frames per second.

I would use the debugger and check the values for image_index to check if they are changing as expected to start with.
 

Megax60

Member
I tried this and it completely stopped the animation if it was anything lower than 1... :\
This works perfectly in GM 1.4, i've recreated your game, i've erased "image_speed = 1" from step event and added image_speed = 0.25 in create event, but i dont know how GM 2 works :L
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
What @TsukaYuriko said applies for 1.4.

However in GMS 2, image_speed is actually a multiplier of the speed that you set in the sprite editor.

So if you set the frames per second to 15 and the image_speed to 1, final speed in game is 15 * 1 = 15

image_speed of 0.5 in GMS 2 would result in 15 * 0.5 = 7.5 frames per second.

I would use the debugger and check the values for image_index to check if they are changing as expected to start with.
Shame on me, call me a noob and shoot me down. I've been using GM:S 2 since it was released and NEVER noticed this. Not even the manual entry mentions it. o_O

Thanks for the correction, I'll edit my post accordingly.
 
R

RCarnival

Guest
Yes I am using GMS2
Using the searching it only shows it being affected if / else coding, it worked perfectly fine in the tutorial but this is seemingly keeping both the sprite for the walk animation and the idle sprite while moving and this is causing it to look like its moving extremely fast but not actually.. how can I correct my code so it will only display the walk animation? Any thoughts I've moved a lot of things around and somehow at some point it was replacing the walk animation with a whole different sprite for the background... I imagine it might have something to do with Image index codes but can't seem to grasp the correlations yet... still learning exactly how it all translates...

Edit: I have figured out my issue... kinda.. I just made some reconfigurements in the movement code rather than the animation code and its working now, it was due to my "hsp" going inbetween 1 & 0 everyframe.. Thanks for all the suggestions!
 
Last edited by a moderator:
Top