SOLVED Sprite does not displayed at the beginning and if i have a collision

Sawyer

Member
Hell erveryone,

I have a little problem, my instance_player have 3 sprites (idle, run and fall)
At the begining or if i collide horizontaly the sprite idle does not display.
If i move the sprite run is displayed then when my hspd = 0 the sprite idle is displayed.
Can you help me?
Create event
GML:
sprite_frame = 0;
sprite = spr_player_idle;
xscale = 1;
yscale = 1;
Step event
Code:
if vspd > 0
{
    sprite = spr_player_fall;
    sprite_frame = 0;
}


if hspd != 0
{
    sprite = spr_player_run;
    sprite_frame += 0.25;
    if sprite_frame >= sprite_get_number(sprite)
    {
        sprite_frame = 0;
    }
}
else
{
    sprite = spr_player_idle;
    sprite_frame = 0;
}
Draw event

Code:
draw_sprite_ext(sprite, sprite_frame, x, y,sign(hspd) * xscale, yscale, 0, c_white, image_alpha);
 

Sawyer

Member
I solved it, thank you
The problem was in draw event, with the sign(hspd). If it was egal to 0, so ifixed it

GML:
var hspd_pos_or_neg = sign(hspd)
if sign(hspd) = 0
{
    hspd_pos_or_neg = 1;
}
draw_sprite_ext(sprite, sprite_frame, x, y,hspd_pos_or_neg * xscale, yscale, 0, c_white, image_alpha);
 
Top