• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Message at mouse tutorial?

Dr_Nomz

Member
I saw a tutorial a long time ago showing how to make a message appear at the mouse, like when you hover over in object (Like in Fallout, or literally any FPS for example.) but now I have no idea where it is or how to do that.

Can anyone help me out? It sounds really simple.
 

Pyxus

Member
I saw a tutorial a long time ago showing how to make a message appear at the mouse, like when you hover over in object (Like in Fallout, or literally any FPS for example.) but now I have no idea where it is or how to do that.

Can anyone help me out? It sounds really simple.
Well, the basic concept would be to check if your mouse is hovering over something with position_meeting or maybe point_in_rectangle. If that check returns true you can then draw text slightly off the mouse's position draw_text(mouse_x, mouse_y+10, "message"). Does that help?
 

Phil Strahl

Member
Just like @Pyxus said :) I once wrote a little "tooltip" parent object that would hold a variable called "tooltip". Anything that would have such a tooltip would be a child object of this obj_tooltip and override the tooltip string, e.g.
Code:
// create event in a child object of obj_tooltip
event_inherit()
tooltip = "Click to close"
When my mouse object would collide with such an object it would read their tooltip variable and display it in a box.
Code:
// in the obj_mouse draw event
var colliding_instance = collision_point(mouse_x, mouse_y, obj_tooltip,false, true
if (colliding_instance != noone)
{
  draw_text(mouse_x, mouse_y - 20, colliding_instance.tooltip)
}
Note: You shouldn't do this check in the draw event, rather in a step event, store the tooltip-string to a variable that lives inside the mouse object and display that. But for simplicity's sake, it works also :)
 
Top