Game Development Community

T2dSceneObject onMouseEnter callback

by Nir Ziso · in Torque Game Builder · 07/16/2006 (1:03 pm) · 11 replies

How can i use the onMouseEnter and onMouseLeave callback on t2dSceneObject
the problem is that those events work just on t2dSceneWindow

#1
07/16/2006 (8:33 pm)
First you have to tell the scene window to use object mouse events, then you have to turn mouse events on for each object you want to use them on. Check out this tutorial.
#2
07/17/2006 (12:51 am)
I did it but still the onMouseLeave callback do not work good
i just want some example that when i am on an object it goes little bit up
(OnMouseEnter) and when i leave the object (onMouseLeave) it goes back to the start position
#3
07/17/2006 (3:50 am)
The callbacks are based on how you define the collision detection for that object. Could you be more specific with your problem? I'm not exactly sure how to answer. If you're talking about making a rollover animation you might consider doing it with animations or just switching the image rather than physically moving the object.
#4
07/17/2006 (3:55 am)
I just want to build asimple card that when i am on the card (OnMouseEnter) it goes aliittle bit up
and when i live the card (onMouseLeave) the card go back to his plase
#5
07/17/2006 (4:10 am)
That you should do with an animation that's triggered by the enter and leave callbacks. As you might have noticed if you shift the position back and forth quickly with the enter and leave callbacks it could cause some problems because you are moving the collision polygon along with the card (for example, when holding the mouse at the bottom edge of the card - it might pop back and forth). You should also edit your collision polygon to fit the card snugly so it's clear to the user where the boundaries are.
#6
07/17/2006 (4:15 am)
Can i do it with t2dImageMapDatablock?
#7
07/17/2006 (4:16 am)
Can i do it with t2dImageMapDatablock?
#8
07/17/2006 (4:20 am)
Can i do it with t2dImageMapDatablock?
#9
07/17/2006 (7:20 am)
I'm gonna suggest you run through the Wack-A-Mole Tutorial that comes with TGB. That should give you an idea of how to set up and trigger animations.
#10
07/17/2006 (7:37 am)
Are you sure there IS an 'onMouseEnter' and 'onMouseLeave' callback for t2dSceneObjects? I only see 'onMouseDown', 'onMouseUp', 'onMouseMove' and 'onMouseDragged' (and the corresponding right mouse callbacks as well). There are 'onMouseEnter' and 'onMouseLeave' callbacks for t2dSceneWindow, though.

When I just tried to implement the enter and leave callbacks in a sceneobject that's already successfully responding to other mouse events, they never get called.

What I've been doing to accomplish the same thing is to use the 'onMouseMove' callback in the t2dSceneObjects to turn an effect 'on', then implemented 'onMouseMove' in t2dSceneWindow to turn it off. I set a boolean flag when I change the state to avoid triggering the 'off' activity unecessarily (only once after the mouse leaves the scene object).

There are also some flags you need to set in both the scene objects and the window object. Call 'setUseMouseEvents(true)' on each of the scene objects, and set the useWindowMouseEvents and useObjectMouseEvents fields in the t2dSceneWindow to true.
#11
07/18/2006 (12:29 am)
I know it
the problem is that the program do not enter to the event onMouseleave
here is my code

function cards::onLevelLoaded(%this, %scenegraph)
{
sceneWindow2D.cards = %this;
// make sure the scene window is set to send mouse events to objects
if(!sceneWindow2D.getUseObjectMouseEvents())
{
sceneWindow2D.setUseObjectMouseEvents(true);
}

// set this object to accept mouse events
%this.setUseMouseEvents(true);

}
function cards::onMousemove(%this,%modifier,%worldPosition,%mouseClicks)
{

%ypos=%this.getPositiony();
if(%ypos==-10)
{
%pos=%this.getPositiony()-2;
%this.setPositiony(%pos);
}
}




function sceneWindow2D::onMouseleave(%this,%modifier,%worldPosition,%mouseClicks)
{
if(isObject(%this.cards))
{
%ypos=%this.cards.getPositiony();
if(%ypos==-12)
{
%pos=%this.cards.getPositiony()+2;
%this.cards.setPositiony(%pos);
echo("change y position to"@%pos);
}
}
}