Login | Register

Tooltip box

July 19, 2006, 12:57 by Calle
[loading]
-->
Try to hold your mouse still over a windows object, such as the start button which brings up the menu, for some time and a little text will be displayed that says “click here to…”, well, this is what I mean by tool tip. This is very useful, even in Game Maker programs or games. It can be achieved through a modification of the famous script_hover:

<div style="clear: both;">text = "Click this button to calculate the meaning of life";
max_width = 100;
draw_sprite(sprite_index,image_single,x,y);
if position_meeting(mouse_x,mouse_y,self)
&& !(mouse_check_button(mb_left)==true) {
draw_set_color(c_dkgray);
draw_rectangle(mouse_x,mouse_y,mouse_x+max_width,mouse_y+
string_height_ext(text,-1,max_width)+20,false);
draw_set_color(c_gray);
draw_text_ext(mouse_x+5,mouse_y+5,text,-1,max_width-5);
}
</div>

In difference to script_hover this script is placed in draw event, but as you can see the first thing I do is drawing the sprite. Thus nothing will visually change the button. I use two color settings; one for the rectangle background and one for the text. This, of course, can changed in any way to create a cool effect. You could even use a background by draw sprite stretched.

Text is the variable that holds the text, of course, and it can be set to anything, of any length, and the rectangle box will automatically resize itself, vertically. You decide the horizontal width. If you like you could do the reverse or simply let the script calculate both values, but usually it’s good to decide one side because that gives symmetry to all of the boxes.

Also note that +20 in the rectangle code is a kind of border I use; so is +5 in the draw text code. This border may be deleted, reduced or enlarged.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games