Jump to content


Photo

Mouse Over Object - Text Boxes


  • Please log in to reply
12 replies to this topic

#1 guitarman4545

guitarman4545

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM:Studio

Posted 23 October 2008 - 04:17 AM

Ive looked everywhere for a tutorial on how to make a small text box that shows a description of an object when the mouse is either moved over an object or clicked on the object. Either way, it sounds simple enough but I couldnt find anything to do with this on this forum, youtube, or any other sites.

Help?
  • 0

#2 candc32

candc32

    GMC Member

  • GMC Member
  • 895 posts

Posted 23 October 2008 - 04:59 AM

it is vary simple:
Create:
show=false
mouse over:
show=true
mouse exit:
show=false
draw:
if show=true
{
	draw_rectangle(mouse_x-100,mouse_y-20,mouse_x,mouse_y,false)
	draw_set_color(c_white)
	draw_text(mouse_x-98,mouse_y-1,"this is text")
}
that is basically it.
  • 1

#3 guitarman4545

guitarman4545

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM:Studio

Posted 23 October 2008 - 05:41 AM

Doesnt work for me... hm :/

What if I wanted the box to show up when hovering over a moving object?

Edited by guitarman4545, 23 October 2008 - 05:49 AM.

  • 0

#4 sycosquirl18

sycosquirl18

    GMC Member

  • New Member
  • 57 posts

Posted 23 October 2008 - 01:40 PM

Doesnt work for me... hm :/

What if I wanted the box to show up when hovering over a moving object?


You have a few options: You can make the text a sprite, and draw the sprite when the mouse is over the object. Or you can make a box with text, like canc32 suggested. Instead of using the "mouse enter" and "mouse leave" events, and using a variable just use the following code in the object that you want the text box for, in the draw event:

if (distance_to_point(mouse_x,mouse_y) == 0)
{
   draw_set_color(c_black);
   draw_rectangle_color(mouse_x-64,mouse_y-48,mouse_x+56,mouse_y+48,c_ltgray,c_ltgray,c_ltgra
y,c_ltgray,false);
   draw_rectangle(mouse_x-64,mouse_y-48,mouse_x+56,mouse_y+48,true);
   draw_set_halign(fa_center);
   draw_set_valign(fa_middle);
   draw_text(mouse_x,mouse_y,"Text goes here.");
}

The important part is the "distance to point" because this returns the distance from the OUTSIDE EDGE of you object to the mouse position. The rest of the code is just drawing the box, centering the text, etc. Also, you probably know this, but if you put things in the draw event, it will not draw a sprite anymore. So draw the sprite yourself, in the draw event. "draw_sprite()" or "draw_sprite_ext()" should do it, just make sure you draw it before you draw the box code above, or the sprite will be on top of the box. Ok, hope that helps, and good luck.
  • 1

#5 guitarman4545

guitarman4545

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM:Studio

Posted 23 October 2008 - 08:54 PM

Edit: Wow sorry for the confusion. I just realized that I don't need the text box to show up on the object, but in a defined spot, the same spot everytime. But I still don't know how to make a text box pop up when you click on an object (instead of hover). Sorry for the confusion, I had a change in setup. :/

Btw sycosquirl, I tried that and says I needed Pro. Thanks for the help, but I dont have Pro quiet yet. :whistle:

Edited by guitarman4545, 23 October 2008 - 10:06 PM.

  • 0

#6 guitarman4545

guitarman4545

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM:Studio

Posted 25 October 2008 - 07:43 PM

Bump (sorry)

Let me restate my question. I need to be able to click a moving object, and a text box will pop up in a defined position everytime. (Not relative to the object) Any ideas?
  • 0

#7 Mnementh

Mnementh

    15151

  • Retired Staff
  • 6261 posts
  • Version:GM:Studio

Posted 25 October 2008 - 07:45 PM

The solution candc32 provided would work, using the mouse pressed and mouse released events instead of the mouse enter and mouse leave events.

Edited by Mnementh, 25 October 2008 - 07:45 PM.

  • 0

#8 TemplarX2

TemplarX2

    GMC Member

  • GMC Member
  • 93 posts

Posted 31 March 2010 - 07:22 AM

Doesnt work for me... hm :/

What if I wanted the box to show up when hovering over a moving object?


You have a few options: You can make the text a sprite, and draw the sprite when the mouse is over the object. Or you can make a box with text, like canc32 suggested. Instead of using the "mouse enter" and "mouse leave" events, and using a variable just use the following code in the object that you want the text box for, in the draw event:

if (distance_to_point(mouse_x,mouse_y) == 0)
{
   draw_set_color(c_black);
   draw_rectangle_color(mouse_x-64,mouse_y-48,mouse_x+56,mouse_y+48,c_ltgray,c_ltgray,c_ltgra
y,c_ltgray,false);
   draw_rectangle(mouse_x-64,mouse_y-48,mouse_x+56,mouse_y+48,true);
   draw_set_halign(fa_center);
   draw_set_valign(fa_middle);
   draw_text(mouse_x,mouse_y,"Text goes here.");
}

The important part is the "distance to point" because this returns the distance from the OUTSIDE EDGE of you object to the mouse position. The rest of the code is just drawing the box, centering the text, etc. Also, you probably know this, but if you put things in the draw event, it will not draw a sprite anymore. So draw the sprite yourself, in the draw event. "draw_sprite()" or "draw_sprite_ext()" should do it, just make sure you draw it before you draw the box code above, or the sprite will be on top of the box. Ok, hope that helps, and good luck.


distance_to_point() is really great when dealing with moving objects. Thanks for this, Syco.
  • 0

#9 vidokas

vidokas

    GMC Member

  • GMC Member
  • 192 posts
  • Version:GM8

Posted 03 February 2012 - 10:30 PM

it is vary simple:
Create:

show=false
mouse over:
show=true
mouse exit:
show=false
draw:
if show=true
{
	draw_rectangle(mouse_x-100,mouse_y-20,mouse_x,mouse_y,false)
	draw_set_color(c_white)
	draw_text(mouse_x-98,mouse_y-1,"this is text")
}
that is basically it.


i tried to make. that when enter pointer on object a textbox appears.
but when i wrote those commands on object_A. i dont see the object_A
but if i enter on them, message appears.

what i'm doing wrong?
  • 0

#10 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 03 February 2012 - 10:32 PM

Make sure to remember to use draw_self() so that your object does not disappear.
  • 1

#11 vidokas

vidokas

    GMC Member

  • GMC Member
  • 192 posts
  • Version:GM8

Posted 04 February 2012 - 09:25 AM

Make sure to remember to use draw_self() so that your object does not disappear.

at position 1: Unknown function or script: draw_self

tried to write that code in create event and draw event (before "if show=true...." command


EDIT:info from wiki about draw_self "This function is a new function in Game Maker 8.1. "
so i guess, i go and try to update my game maker

EDIT2: tried with 8.1. it works now.

THANKS!

Edited by vidokas, 04 February 2012 - 09:44 AM.

  • 0

#12 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 04 February 2012 - 05:33 PM

Sure, glad it worked out for you! Posted Image
  • 0

#13 Kitskull

Kitskull

    GMC Member

  • New Member
  • 11 posts
  • Version:Unknown

Posted 20 July 2012 - 05:07 AM

I asked the same question. But no one replied!! >:( did the first solution work for everyone? Because I'm making an inventory label thing
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users