Legacy GM [FIXED] Help needed with Mouse over objects

Shavv

Member
Heey!

I made this little code to draw an outline over one object and one only. It works but when i mouse over multiple objects at the same time, none of them get shown.

Code:
///outline(color,mousemask,normalmask)
mask_index=argument1

if position_meeting(mouse_x,mouse_y,self)
{
 if global.mouse_over=id
 {
  //Set an outline color
  var outline_color = argument0;
  d3d_set_fog(1,outline_color,-1,-1)
  //Draw the sprite 1 pixel off in each direction
  draw_sprite_ext(sprite_index, -1, x - 1, y, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x + 1, y, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x, y - 1, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x, y + 1, image_xscale, image_yscale, 0, outline_color, 1);
  d3d_set_fog(0,0,0,0)
  //set target
  if mouse_check_button_pressed(mb_right)
  {
   obj_player.target=id
  }
 }
 global.mouse_over=id
}

mask_index=argument2
I use the mask for getting a different collision for the mouse and the movement collision.

I want to make the object with the lowest depth value the one that gets an outline.



Thanks for the help!
 
I recommend NEVER using the keyword "self". Doubt it's your problem, but it's a good idea, regardless. Instead, use "id".

As for your layering problem, I believe @uheartbeast might have a video that could help you out.
 

Shavv

Member
I recommend NEVER using the keyword "self". Doubt it's your problem, but it's a good idea, regardless. Instead, use "id".

As for your layering problem, I believe @uheartbeast might have a video that could help you out.
Thank you for your fast repsonse, tho i think this method is such a wayaround. I would like to have one clean code instead of a whole ds_list of the objects i created just to get the top one.

Here i should note that i used depth=-y for my objects. So that would be easier to divide them.

I also have more the issue now that it selects none instead of one of the objects with a random depth.
 

Shavv

Member
I fixed it by applying another statement:

Code:
if global.mouse_over=id or (global.mouse_over!=id and global.mouse_over.depth>depth)
For the interested: So the total code should look like this

Code:
///outline(color,mousemask,normalmask)
mask_index=argument1

if position_meeting(mouse_x,mouse_y,self)
{
 if global.mouse_over=id or (global.mouse_over!=id and global.mouse_over.depth>depth)
 {
  //Set an outline color
  var outline_color = argument0;
  d3d_set_fog(1,outline_color,-1,-1)
  //Draw the sprite 1 pixel off in each direction
  draw_sprite_ext(sprite_index, -1, x - 1, y, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x + 1, y, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x, y - 1, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x, y + 1, image_xscale, image_yscale, 0, outline_color, 1);
  d3d_set_fog(0,0,0,0)
  //set target
  if mouse_check_button_pressed(mb_right)
  {
   obj_player.target=id
  }
 }
 global.mouse_over=id
}

mask_index=argument2
EDIT: nvm doesnt work rip
 
Last edited:
Hmm... I'm a little concerned that this only "appears" to work because of the order your instances are executing their code in. I could be wrong, but looking at this that is the feeling I get.

If it works for you and continues to work for you, great I guess... but I think this is going to break eventually.
 

Shavv

Member
Hmm... I'm a little concerned that this only "appears" to work because of the order your instances are executing their code in. I could be wrong, but looking at this that is the feeling I get.

If it works for you and continues to work for you, great I guess... but I think this is going to break eventually.
@Pixelated_Pope you are absolutely right. It only appeared to be working for a moment until i noticed something sketchy.



The first two instances worked like i wanted it to, but when i mouse-overed the 3rd one. I got the same issue sadly.
 
This works:
Code:
///outline(color,mousemask,normalmask)
mask_index=argument1
if position_meeting(mouse_x,mouse_y,self)
{
 if(global.mouse_over!=id){
    if(instance_exists(global.mouse_over)){
        if(global.mouse_over.depth>depth){
            global.mouse_over=id;
        }
    }else{
        global.mouse_over=id;
    }
 }
 if global.mouse_over=id
 {
  //Set an outline color
  var outline_color = argument0;
  d3d_set_fog(1,outline_color,-1,-1)
  //Draw the sprite 1 pixel off in each direction
  draw_sprite_ext(sprite_index, -1, x - 1, y, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x + 1, y, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x, y - 1, image_xscale, image_yscale, 0, outline_color, 1);
  draw_sprite_ext(sprite_index, -1, x, y + 1, image_xscale, image_yscale, 0, outline_color, 1);
  d3d_set_fog(0,0,0,0)
  //set target
  if mouse_check_button_pressed(mb_right)
  {
   //obj_player.target=id
  }
 }
}else{
    if(global.mouse_over==id){
        global.mouse_over=noone;
    }
}
mask_index=argument2
 

Shavv

Member
///outline(color,mousemask,normalmask) mask_index=argument1 if position_meeting(mouse_x,mouse_y,self) { if(global.mouse_over!=id){ if(instance_exists(global.mouse_over)){ if(global.mouse_over.depth>depth){ global.mouse_over=id; } }else{ global.mouse_over=id; } } if global.mouse_over=id { //Set an outline color var outline_color = argument0; d3d_set_fog(1,outline_color,-1,-1) //Draw the sprite 1 pixel off in each direction draw_sprite_ext(sprite_index, -1, x - 1, y, image_xscale, image_yscale, 0, outline_color, 1); draw_sprite_ext(sprite_index, -1, x + 1, y, image_xscale, image_yscale, 0, outline_color, 1); draw_sprite_ext(sprite_index, -1, x, y - 1, image_xscale, image_yscale, 0, outline_color, 1); draw_sprite_ext(sprite_index, -1, x, y + 1, image_xscale, image_yscale, 0, outline_color, 1); d3d_set_fog(0,0,0,0) //set target if mouse_check_button_pressed(mb_right) { //obj_player.target=id } } }else{ if(global.mouse_over==id){ global.mouse_over=noone; } } mask_index=argument2
Sadly doesnt work at all. Now it doesnt even show a outline.
 

Shavv

Member
Works for me perfectly. Make sure to set global.mouse_over to noone at the start. Is there any other code that is changing this variable?
Ah indeed, the global.mouse_over wasnt at noone at the beginning this did the trick. Thank you for your effort. It works like a charm now.
 
Ah indeed, the global.mouse_over wasnt at noone at the beginning this did the trick. Thank you for your effort. It works like a charm now.
No problem. Actually, I notice if you're going from bottom to top across 3 that are overlapping, the top one flashes before the middle one stays outlined. I'll see if I can fix that.
 
Top