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

draw_sprite animated

J

JON213

Guest
Hello. I am trying to use the draw sprite function but it is not animating. It draws the first frame of the sprite and doesn't loop through the animation. I am running the code below in the draw event.
Code:
draw_sprite(spr_Player_head_idle,image_index,x,y-3);
draw_sprite(spr_Player_torso_idle,image_index,x,y+2);
draw_sprite(spr_Player_legs_idle,image_index,x,y+7);
 

StormGamez

Member
if you want it to animate you will have to change the "image_index" with a variable, some thing along the lines of this:
Code:
//Step event
//Change the value to either speed up the animation or slow it down
sprite_num+=1

//Draw event
draw_sprite(spr_Player_head_idle,sprite_num,x,y-3);
draw_sprite(spr_Player_torso_idle,sprite_num,x,y+2);
draw_sprite(spr_Player_legs_idle,sprite_num,x,y+7);
 
Did you set the image_speed variable to 0 anywhere else in your code? Do the sprite assets themselves have a image speed defined in their editor? If you are using image_index that shouldn't be a need to use another variable.
 

obscene

Member
Here's probably what's happening:

Apart from the sprites you are trying to draw, you have a sprite assigned to this object. That sprite specifically sets the value of image_last based on how many frames that sprite has. image_index will then advance by image_speed every step until it reaches image_last and then it repeats. If that sprite has only one frame, image_index will just remain at 0, regardless of how many frames those three sprites have.

If this is what's happening, you just need to use your own custom variable instead of image_index and create some code to add to it each frame and reset it back to 0 when it reaches whatever value you need.
 
Top