• 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!

Legacy GM Sprite drawing flashing issue [SOLVED]

Tuna

Member
I have been trying for a while now to draw a melee weapon on my character, but whenever I have its position change throughout an animation, the weapon sprite flashes, sometimes for multiple frames. As you can see in this recording, the sprite is normal when being drawn as a single frame (standing or ducking) but it looks bad when moving frame-by-frame (walking or attacking).

Here is the code in the draw event of obj_player. It controls all of the weapon drawing:

if sprite_index == spr_walk_sword_pistol{

if image_index == 0{
draw_sprite_ext(hold,0,x+(12*image_xscale),y-4,1,1,45*image_xscale,c_white,1);
}

if image_index == 1{
draw_sprite_ext(hold,0,x+(11*image_xscale),y-3,1,1,45*image_xscale,c_white,1);
}

if image_index == 2{
draw_sprite_ext(hold,0,x+(10*image_xscale),y-2,1,1,45*image_xscale,c_white,1);
}

if image_index == 3{
draw_sprite_ext(hold,0,x+(9*image_xscale),y-2,1,1,45*image_xscale,c_white,1);
}

if image_index == 4{
draw_sprite_ext(hold,0,x+(10*image_xscale),y-1,1,1,45*image_xscale,c_white,1);
}

if image_index == 5{
draw_sprite_ext(hold,0,x+(10*image_xscale),y-2,1,1,45*image_xscale,c_white,1);
}

//draw hand over weapon
draw_sprite_ext(spr_walk_sword_hand,image_index,x,y,image_xscale,1,0,c_white,1);
}
 
Last edited:
Also you don't need to use if statements like this. If you are doing many different things for many different values of a certain variable, use a switch statement.

Code:
switch (round(image_index)) {

case 0:
draw_sprite_ext(hold,0,x+(12*image_xscale),y-4,1,1,45*image_xscale,c_white,1);
break;

case 1:
draw_sprite_ext(hold,0,x+(11*image_xscale),y-3,1,1,45*image_xscale,c_white,1);
break;

case 2:
draw_sprite_ext(hold,0,x+(10*image_xscale),y-2,1,1,45*image_xscale,c_white,1);
break;

case 3:
draw_sprite_ext(hold,0,x+(9*image_xscale),y-2,1,1,45*image_xscale,c_white,1);
break;

case 4:
draw_sprite_ext(hold,0,x+(10*image_xscale),y-1,1,1,45*image_xscale,c_white,1);
break;

case 5:
draw_sprite_ext(hold,0,x+(10*image_xscale),y-2,1,1,45*image_xscale,c_white,1);
break;

}

//draw hand over weapon
draw_sprite_ext(spr_walk_sword_hand,image_index,x,y,image_xscale,1,0,c_white,1);
If the animation is off a bit, use Floor or Ceil for the image_index. I don't remember which one should work.
 
Happy to help!

Game maker increments image_index by image_speed every frame. The draw_sprite_ext script will floor the value for the index you pass into it. So if you're image_speed is 0.25, an image_index can be something like (3.25, 3.50, 3.75) ,but the actual displayed index is 3. So if you're checking if image_index == 3, that'll only happen once in a while.

You probably figured that out, but I just thought I'd clarify.
 
Top