Game Development Community

Mouse over tile

by Richard Petrov · in Torque Game Builder · 10/29/2011 (9:44 am) · 5 replies

Hello,

I'm working on a project that requires the ability to know which tile the mouse is over so I can highlight it. I tried thinking about using:

sceneWindow2D.setUseMouseEvents(true); // in StartGame(%level) function

//below is what I put in mainScreen.gui
useWindowMouseEvents = "1";
useObjectMouseEvents = "1";

for the sceneWindow2D (mainScreen.gui) to get the mouse coordinates. It doesn't seem to trigger the function:


// I put this function in game.cs at the bottom for testing purposes only
function sceneWindow2D::onMouseMove( %this, %modifier, %worldPos, %mouseClicks )
{
    echo ("Mouse Move!");  
}

I searched the forums for a solution, but couldn't find anything that worked. Any suggestions or ideas?

#1
10/29/2011 (10:16 am)
Almost every time I ask a question on these forums when I'm stuck I find an answer within the first hour.

I found out the problem. I push a Hud GUI on top of the sceneWindow2D and it won't get any mouse movements then. Is there an alternative to creating a HUD then through GUI or should I just attach the mouse move the GUI over sceneWindow2D?
#2
10/29/2011 (12:52 pm)
Do you need to interact with the GUI HUD with the mouse? If not, you can set it's datablock to be modal=false and to not use the mouse events (set those to "0").

If you do need to interact with the top layers, check out replies #4 and #13 in this post: www.garagegames.com/community/forums/viewthread/109707
#3
10/31/2011 (10:04 am)
nevermind.. was what William suggested. :)

#4
10/31/2011 (12:26 pm)
Thanks for the replies. don't need to interact with the GUI Hud with the mouse. I set the datablock to modal=false and mouse events to 0 but still no luck.

This is what I have for the Hud.

//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(GameGUI) {
   canSaveDynamicFields = "0";
   isContainer = "1";
   Profile = "GuiDefaultProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   Position = "0 0";
   Extent = "640 320";
   MinExtent = "8 2";
   canSave = "1";
   Visible = "1";
   hovertime = "1000";
   modal = "0";
   useWindowMouseEvents = "0";
   useObjectMouseEvents = "0";

   new GuiTextCtrl(VictimHealthLabel) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiTextProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      Position = "184 277";
      Extent = "94 38";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      text = "Nothing yet";
      maxLength = "1024";
   };
   new GuiTextCtrl(VictimHealth) {
      canSaveDynamicFields = "0";
      isContainer = "0";
      Profile = "GuiTextProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      Position = "280 289";
      Extent = "64 15";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      text = "100";
      maxLength = "1024";
   };
};
#5
11/01/2011 (11:41 am)
Ugh, nevermind. I started working on my project today and the entire level I had created went black. In Torque2D I can highlight some things, and if I go edit my tilemap it's purple. Everything is black and gone. :-/ I may scrap the engine and start some place else.