Game Development Community

Using object mouse events

by J Sears · in Torque Game Builder · 12/02/2006 (10:14 pm) · 8 replies

I've been trying to get object mouse events to work, and as I understand it I need to setUseObjectMouseEvents(true); it tells me this function doesn't exist I've tried it just as is and with t2dScene which is the name of my scene in front of it as t2dScene.setUseObjectMouseEvents(true); how do you get this to work?

#1
12/03/2006 (1:41 am)
sceneWindow2D.setUseObjectMouseEvents(true);   //in most cases - don't really
					       //understand windows vs. graphs
                                               // and their defaults
                                               //but this works for me ;)

And don't forget to activate mouse events on the objects you want to get events too.

Hope that works for you!
#2
12/03/2006 (9:50 pm)
That did end up working right but here's my new question now, I am using this on cards that are fanned out in the way people normally hold their cards so they are overlapping, I want the click to register the top most card that it's clicked on and this does the bottom most, now I know I can do this using the scenewindow object events instead but then I have to go through a search of all objects under the clicked mouse and that seems like a waste if there's an easy way to make this register the click on the top most card
#3
12/03/2006 (10:40 pm)
Use pickPoint() and get all underlaying scene objects. The only you have to is choose appropriate one. Enjoy.
#4
12/03/2006 (11:16 pm)
Thank you I got it to work that way, was just hoping I wouldn't have to do an object search the same was as with scenewindow mouse clicks
#5
12/06/2006 (12:42 pm)
Hello,

I'm trying to add mouse movement to the Fish game in the tutorials.
I've added

sceneWindow2D.setUseObjectMouseEvents( true );
Canvas.hideCursor();

to my startGame function in game.cs. Then, I added

function sceneWindow2D::onMouseMove(%this, %mod, %worldPosition) 
{  
   PlayerFish.setPosition(%worldPosition); 
}

also to game.cs

I don't know if anything else should be added, but at the moment the fish slowly dies, without any movement at all.

Thanks for any help
#6
12/06/2006 (12:49 pm)
If you add an echo to the onMouseMove function and check the console you can see if the problem lies with the callback not getting called or if it's your PlayerFish object that's the problem.

If you haven't played around with echoes and the console, the "Basic Debugging" Component Tutorial in the new docs (1.1.3 if you haven't updated) goes over how to use those tools.
#7
12/06/2006 (12:58 pm)
I had a look at the console, and I found the message

PlayerFish : Unable to find object

Any idea how I can reference the PlayerFish (which I've just declared as being the class of the object in the editing tool)?
I'll have a go at giving it a name. Maybe that might help.

Thanks for the (very) quick answer. under 2 minutes I think.
#8
12/06/2006 (1:00 pm)
It worked. Thanks for the hint about the console. I should be looking faster at the thing.