Can I draw_sprite from a script?

Can I draw a sprite from within a script? I can't seem to get it to work. I know the script is running because I can get the messagebox to pop up.


///@description Makes sprite hover on cursor for placement
///@arg sprite

var sprite = argument0;
var xx = mouse_x;
var yy = mouse_y;

draw_sprite(sprite, 0, xx, yy);

show_message("it worked");

if mouse_check_button_pressed(mb_left) {


There's something I'm doing wrong, I can get a sprite to pop up for a sec using the draw or draw to gui, then it disappears. I've searched for help with the draw_sprite function, but even when calling it from the draw event, I can't seem to get it to stay and be where it is supposed to be.

In the draw to gui event:

if mouse_check_button_pressed(mb_left) {
draw_sprite(spr_object, 0, mouse_x, mouse_y);



🐧 *penguin noises*
GMC Elder
if mouse_check_button_pressed(mb_left) {
All the pressed and released functions only are true for one frame (when the button's state switches between "held down" and "idle") so if you want the indication to last longer than that, you'll need to add your own variable. (E.g. when pressing, you set the ButtonGlow variable to 20. Each step, if it's larger than zero, you draw the sprite and also reduce it by 1. Thus, after 20 steps, it's back at zero and the drawing ends)
Okay, so how about if, when I create an object, I create a variable that keeps the object at mouse__x, and mouse_y. Then, with a left click button I "place" the object "permanently" in the room. I can make that variable false, but how should I grab that x, y coordinate and plant it as the objects home? I'm guessing I make a variable for that location, but how do I hand off that number without referring to mouse_x and mouse_y?

if placing {

x = mouse_x;
y = mouse_y;

if mouse_check_button_pressed(mb_left) {

placing = false;

if placing = false {
x = ????
y = ????
I'd like to place it perminently in the room. At a button click, I'd like it to not follow mouse_x and mouse_y any more. Basically, clicking to place an object.
Okay so I got it to work with a mb_right instead of left. It's seeing the first mb_left click and instantly placing it. Is it common to set a cool down so that mb_left can't be recognized for a second or so?


I'd like to place it perminently in the room.
Typically, what is placed "permanently" in a room are not sprites, but instances, which may or may not draw sprites every frame to give the desired effect, using state variables that are perhaps influenced by user input. You could use an Asset layer if you really want a sprite to be more permanently placed, but in this case it seems more appropriate to conditionally draw using state information by an instance's draw event.

I'd split the task in two parts. Figure out how you want to manage the state (a single boolean variable, or something else more complex, depending on additional needs), and then figure out how you want to use the mouse events to change this state information (this can include having a "cooldown" timer/countdown variable to disallow the state from changing until a certain amount of time/frames has passed). Decouple the direct checking of the mouse from your display code and use the state as the intermediary.

Either use the step or the mouse events, according to your preference, for checking the user input and change state as needed, and leave the draw events to only work with the current state information without looking at user input.