• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker image_speed doesn't work

F

Freppe

Guest
Hi everyone. I just started using GameMaker a while ago and so far I haven't met any unusual problems, well until now. Everything in my script seems to work well except for the "Slashing" part. The idea is that the attached arm will turn invisible while my sprite begins it's slashing animation. My problem is that even though I set the image_speed to 15 nothing happens. The sprite has no animation otherwise which means its frame speed is set to 0 in the sprite menu. But that shouldn't stop me from changing it right?
Either way here's my code:

Create event:
Code:
spd = 6;
walkspd = spd;
diagspd = round(spd * ((sqrt(2)) / 2))
cooldown = 0;
hp = 5;
attached = 0;
ammo = 7;
direction = point_direction(x,y,mouse_x,mouse_y);
image_angle = direction;

with (instance_create_layer(x,y,"Instances",obj_arm)) attached = other.id;
Step event:
Code:
//Movement
direction = point_direction(x,y,mouse_x,mouse_y);
image_angle = direction;

if (keyboard_check(vk_lshift)) {
    spd = 2;
    with (obj_enemy) sneaking = true;
} else spd = 6;

walkspd = spd;
diagspd = round(spd * ((sqrt(2)) / 2))

rkey = keyboard_check(ord("D"));
lkey = keyboard_check(ord("A"));
ukey = keyboard_check(ord("W"));
dkey = keyboard_check(ord("S"));

hsp = (rkey - lkey) * spd;
vsp = (dkey - ukey) * spd;

//Collisions
if (hsp != 0)
if (place_meeting(x+hsp,y,obj_collision)) {
    if (hsp > 0) move_contact_solid(0,hsp);
    if (hsp < 0) move_contact_solid(180,-hsp);
    hsp = 0;
}

if (vsp != 0)
if (place_meeting(x,y+vsp,obj_collision)) {
    if (vsp > 0) move_contact_solid(270,vsp);
    if (vsp < 0) move_contact_solid(90,-vsp);
    vsp = 0;
}

x += hsp;
y += vsp;

//Diagonal Movement
if (vsp != 0 && hsp != 0) {
    spd = diagspd;
} else {
    spd = walkspd;
}

//Shooting
var xx = attached.x + lengthdir_x(90,attached.image_angle);
var yy = attached.y + lengthdir_y(90,attached.image_angle);
var originDir = attached.direction;
var originAngle = attached.image_angle

if (mouse_check_button(mb_left) && cooldown < 1 && ammo > 0) {
    with (instance_create_layer(xx,yy,"BulletsLayer",obj_bullet)) {
        direction = originDir;
        image_angle = originAngle;
    }
    audio_sound_pitch(snd_bullet,random_range(0.9,1.1));
    audio_play_sound(snd_bullet,0,0);
    cooldown = 40;
    ammo--;
    with (obj_crosshair) ammo--;
}

if (keyboard_check_pressed(ord("R")) && ammo < 7 && !alarm[0]) {
    alarm[0] = 120;
    audio_play_sound(snd_reload,2,false);
}
cooldown--;

//Slashing

if (keyboard_check_pressed(ord("F"))) {
    attached.image_alpha = 0;
    image_speed = 15;
}

if (hp < 1) game_restart();
 

Attachments

T

TimothyAllen

Guest
I didn't even look at your code, but an image_speed of 15 means that the animation will play at 15x speed! So it is likely animating so fast that most frames are just skipped.
 
F

Freppe

Guest
I didn't even look at your code, but an image_speed of 15 means that the animation will play at 15x speed! So it is likely animating so fast that most frames are just skipped.
I have tried lower speeds but there is no difference.
 

CMAllen

Member
How lower? Try a value between 0 and 1.
1 is 100% speed. 2 is 200% speed. And 0 stops animating the sprite. Note: if you set a sprite's animation speed to 0 *in the sprite's settings* it will not and cannot animate until you give it a speed greater than 0. 0 frames per step or per second is no animation, no matter how high you set the multiplier. To change this you need to change the base sprite's animation speed with sprite_set_speed() -- Note: this will change the animation speed for ALL instances using this sprite because it is changing the sprite's base properties.
 
F

Freppe

Guest
1 is 100% speed. 2 is 200% speed. And 0 stops animating the sprite. Note: if you set a sprite's animation speed to 0 *in the sprite's settings* it will not and cannot animate until you give it a speed greater than 0. 0 frames per step or per second is no animation, no matter how high you set the multiplier. To change this you need to change the base sprite's animation speed with sprite_set_speed() -- Note: this will change the animation speed for ALL instances using this sprite because it is changing the sprite's base properties.
Thank you so much!
To fix it without disrupting other instances with the same sprite I simply gave the sprite a speed and then set image_speed to 0 in the create event. This allowed me to activate the animation later on in the step event by increasing image_speed again.
 
Top