How to display an outline around an object on mouse over?

V

vincenttnecniv

Guest
Hello GM community! I've watched a ton of tutorials on how to do something similar to what I want, but nothing really gets it just right. Basically I want to mouse over my object in the room, and have an outline sprite appear animated around my object. My code so far is

if position_meeting(mouse_x, mouse_y, obj_test) {
draw_sprite(spr_selected, image_index, mouse_x, mouse_y);
}

obj_test is my object, and spr_selected is my sprite. Right now it does nothing when i mouse over them. Idk what im doing wrong. This is all written in a step event in the object.
 

FrostyCat

Redemption Seeker
Did any of those videos teach you that drawing functions have no effect outside Draw-type events? This is as basic as GM theory gets.

Move this code into the Draw event and draw it at the right place for once.
Code:
if (position_meeting(mouse_x, mouse_y, id)) {
  draw_sprite(spr_selected, image_index, x, y);
}
else {
  draw_self();
}
 
V

vincenttnecniv

Guest
I forgot about the draw event. My bad. When I do what you suggested it replaces the object with the sprite. That's not what im going for. I'm trying to outline my object. Leaving the center of the other sprite blank still removes the sprite from the original object.
 
A

Aura

Guest
Did you try figuring out what draw_self() does? It needs to be called in both the cases, otherwise the original sprite would not be drawn if you're to hover the cursor over the instance.

Code:
if (position_meeting(mouse_x, mouse_y, id)) {
   draw_self();
  draw_sprite(spr_selected, image_index, x, y);
}
else {
  draw_self();
}
 
Top