draw_sprite animation speed

K

Kroan

Guest
Hi,

I have an enemy object that the player can focus on.
When an enemy is focused I want to draw a marker on it (a rotating circle to indicate that the enemy is focused)

I thought I could do that within the Draw event of the enemy object, however the animation speed of the circle is extremely fast.
The circle is animating fine in the sprite editor (I put it on a speed of 5 Frames per second.)
Here is what I tried:

Create of enemy
GML:
isFocused = false;
focusedMarker = sEnemyTargetMarker;
focusedMarker.image_speed = 1;
Draw event of enemy
Code:
draw_self();
if(isFocused)
{
    draw_sprite(focusedMarker,focusedMarker.image_index,x,y);
}
I read that the image_speed is responsible for the multiplication of the speed so I set it to 1 for the focusedMarker but it doesn't make any difference.
Any help?

Thanks!
 

Datky

Member
With an image_speed of 1, every frame the animation is gonna change, which is 60 times/second. That's generally way too fast.
If you want 5 frames/seconds, you need to put image_speed to
GML:
1/(room_speed/5)
This should work better
 
Is focusedMarker an object or a sprite? image_index is for getting the frame from an instance.

Sprites don't have universal indexes since objects are pulling different frames at different times. The reason it doesn't throw an error is because each sprite has an number id (0,1,2,etc.) just like object id.
sEnemyTargetMarker.image_index is actually targeting whatever object shares it's number.

If you want multiple sprites in one object, you'll need to make your own animation frame and speed variables for each one.
 
Last edited:

TheouAegis

Member
GML:
isFocused = false;
focusedMarker = 0;
GML:
draw_self();
if(isFocused)
{
     draw_sprite(sEnemyTargetMarker,++focusedMarker div 12,x,y)
}
 
K

Kroan

Guest
@Datky
I was afraid that something like that ist the way to go, feels a bit counter intuitive to programmatically calculate the animation speed again after already setting it up in the sprite editor. Perhaps I was just hoping for more "magic" going on with GMS :D thank you I'll try it.

@Terminator_Pony
Thank you for the detailed explanation, great learning!

@TheouAegis
Thanks for taking the time to respond. Would you mind some explanation? What is div doing and where is the magic 12 coming from?

Thank you all!
 
Top