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

Discussion in 'Programming' started by vincenttnecniv, Aug 13, 2016.

  1. 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.
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,552
    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();
    }
     
    41nd and studio furukawa like this.
  3. 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.
     
  4. Aura

    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();
    }
     
  5. koffe

    koffe Guest

    yuck, ugly attitude on this one

    ---
    thanks for the help aura
     
    Triangle and Dan B like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice