• 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 Setting image_speed on a draw_sprite_ext()

G

Gregory Tapper

Guest
Hi!

Having trouble animating a sprite I'm drawing. Setting image_speed in the create/draw event doesn't seem to be doing anything. The sprite remains static :( The object itself is a parent object that draws an animated river sprite (2 frames) and then itself (the children will draw static river edges).

Here's the code in the Draw Event :
Code:
draw_sprite_ext(spr_river,image_index,x,y,1,1,0,col,1);
image_speed = 1;
draw_self();
Any suggestions? Thank you!
 

Simon Gust

Member
I believe that the image_speed is just too high.
You have set it to an insane speed for only 2 frames of animation.
Try 0.12
 
G

Gregory Tapper

Guest
I believe that the image_speed is just too high.
You have set it to an insane speed for only 2 frames of animation.
Try 0.12
Ahh, good suggestion. But nope :( I tried 0.01 too just to be sure.
 

NightFrost

Member
Do you have any code in step event or scripts it calls that set image_index value? Setting your animation speed through image_speed helps you none if a piece of code elsewhere interferes by setting the current animation frame.
 
G

Gregory Tapper

Guest
Do you have any code in step event or scripts it calls that set image_index value? Setting your animation speed through image_speed helps you none if a piece of code elsewhere interferes by setting the current animation frame.
Unfortunately, it was just added. Hasn't been manipulated anywhere else yet.
 

Perseus

Not Medusa
Forum Staff
Moderator
The problem here is that you're using image_index for its subimage argument. Since the child object running this code has been assigned a sprite that has a single subimage only, image_index can never be larger than 0, regardless of what image_speed is being set to. This causes your animated spr_river sprite to be drawn static as its first (index 0) subimage.

The solution is to use a custom instance variable whose value is to be incremented and reset as per your needs. For instance, the current setup can be fixed using a variable that sets its value this way every step:
Code:
my_image = 1 - my_image;
 
G

Gregory Tapper

Guest
The solution is to use a custom instance variable whose value is to be incremented and reset as per your needs. For instance, the current setup can be fixed using a variable that sets its value this way every step:
Code:
my_image = 1 - my_image;
Thank you @Ragarnak ! This worked! And thanks for the explanation.

For anyone running into the same issue, here's what I did:

Code:
//Create Event
imgdex = 0;
river_speed = room_speed/2;
alarm[0] = river_speed;
Code:
//Step Event
image_index = imgdex;
Code:
//Alarm[0]
imgdex = 1 - imgdex;
alarm[0] = river_speed;
Code:
//Draw Event
draw_sprite_ext(spr_river,image_index,x,y,1,1,0,-1,1);
draw_self();
 

Perseus

Not Medusa
Forum Staff
Moderator
Thank you @Ragarnak ! This worked! And thanks for the explanation.
You're welcome. Glad I could help you.

Just for the record, you can skip using image_index whatsoever. Not only is it a better practice, it also eliminates your chances of running into issues.

Create:
Code:
imgdex = 0;
river_speed = room_speed / 2;
alarm[0] = river_speed;
Alarm 0:
Code:
imgdex = 1 - imgdex;
alarm[0] = river_speed;
Draw:
Code:
draw_sprite_ext(spr_river, imgdex, x, y, 1, 1, 0, -1, 1);
draw_self();
 
Top