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

Is it possible to draw a animated sprite in the Draw GUI event?

B

Bokkie2988

Guest
As the title says, Is it possible to draw a animated sprite in the Draw GUI event? Because now, when I draw the sprite, it only plays the first frame.

Thank you for anyone that can help.
 

samspade

Member
As the title says, Is it possible to draw a animated sprite in the Draw GUI event? Because now, when I draw the sprite, it only plays the first frame.

Thank you for anyone that can help.
Yes, just use draw_self() or any of the draw_sprite functions in the GUI draw event (make sure to disable the basic draw event by putting a blank draw event there). Also remember that the GUI coordinate system is not the same as the room coordinate system.

(as a side note: in generally there is nothing different about the draw and draw gui events. The primary exceptions are that they use different coordinate systems and the draw event is drawn to the application surface, while the GUI is not (meaning they can have different resolutions and functions that modify or require the application surface will not affect the GUI layer for better or worse). There are some others but those are the big ones.)
 
B

Bokkie2988

Guest
Yes, just use draw_self() or any of the draw_sprite functions in the GUI draw event (make sure to disable the basic draw event by putting a blank draw event there). Also remember that the GUI coordinate system is not the same as the room coordinate system.

(as a side note: in generally there is nothing different about the draw and draw gui events. The primary exceptions are that they use different coordinate systems and the draw event is drawn to the application surface, while the GUI is not (meaning they can have different resolutions and functions that modify or require the application surface will not affect the GUI layer for better or worse). There are some others but those are the big ones.)
Yes, I used draw_sprite in the Draw GUI event to draw the animated sprite, but it only plays 1 frame of the sprite and I think thats because it draws it every frame which resets the animation every time. That's what I'm looking a solution for.
 

FrostyCat

Redemption Seeker
The draw_self() and the "-1 in the second argument of draw_sprite()" solutions won't work if the sprite in sprite_index doesn't have the same number of frames as the sprite you're about to draw.

Either you emulate the frame animation process yourself like this:

Create:
Code:
my_sprite = spr_example;
my_sprite_frame = 0;
my_sprite_speed = 1;
Draw GUI:
Code:
my_sprite_frame += my_sprite_speed;
draw_sprite(my_sprite, my_sprite_frame, 32, 32);
Or create a new blank object with a comment-only Draw event and a Draw GUI event with draw_self(), then create an instance of that and set its sprite.
Code:
var inst = instance_create_layer(32, 32, layer, obj_sprite_placeholder);
inst.sprite_index = spr_example;
I've recently started to delegate background tasks to workers (the second approach) instead of hogging it all in the Step event like most others here do (the first approach). The performance impact on my code has thus far been negligible, but the maintainability gains far outweigh the runtime costs.
 
B

Bokkie2988

Guest
The draw_self() and the "-1 in the second argument of draw_sprite()" solutions won't work if the sprite in sprite_index doesn't have the same number of frames as the sprite you're about to draw.

Either you emulate the frame animation process yourself like this:

Create:
Code:
my_sprite = spr_example;
my_sprite_frame = 0;
my_sprite_speed = 1;
Draw GUI:
Code:
my_sprite_frame += my_sprite_speed;
draw_sprite(my_sprite, my_sprite_frame, 32, 32);
Or create a new blank object with a comment-only Draw event and a Draw GUI event with draw_self(), then create an instance of that and set its sprite.
Code:
var inst = instance_create_layer(32, 32, layer, obj_sprite_placeholder);
inst.sprite_index = spr_example;
I've recently started to delegate background tasks to workers (the second approach) instead of hogging it all in the Step event like most others here do (the first approach). The performance impact on my code has thus far been negligible, but the maintainability gains far outweigh the runtime costs.
The second approach worked like a charm! Thank you!
 

TheZampo

Member
The draw_self() and the "-1 in the second argument of draw_sprite()" solutions won't work if the sprite in sprite_index doesn't have the same number of frames as the sprite you're about to draw.

Either you emulate the frame animation process yourself like this:

Create:
Code:
my_sprite = spr_example;
my_sprite_frame = 0;
my_sprite_speed = 1;
Draw GUI:
Code:
my_sprite_frame += my_sprite_speed;
draw_sprite(my_sprite, my_sprite_frame, 32, 32);
Or create a new blank object with a comment-only Draw event and a Draw GUI event with draw_self(), then create an instance of that and set its sprite.
Code:
var inst = instance_create_layer(32, 32, layer, obj_sprite_placeholder);
inst.sprite_index = spr_example;
I've recently started to delegate background tasks to workers (the second approach) instead of hogging it all in the Step event like most others here do (the first approach). The performance impact on my code has thus far been negligible, but the maintainability gains far outweigh the runtime costs.
Just to add up, after all this time.
If anyone has the same problem, the second solution works but can generate multiple instances. So don't forget to test it out if it already exists
Code:
if (!instance_exists(oSpritePlaceholder))
{
    var _inst = instance_create_layer(16, 16, layer, oSpritePlaceholder);
    _inst.sprite_index = sSprite;
}
 
Top