Game Development Community

onTouchEnter( ) behaviour

by Amjad Yahya · in Torque 2D Beginner · 09/29/2013 (10:27 am) · 2 replies

I'm facing a little problem that I need to figure out, in legacy TGB objects onMouseEnter() were called only when the mouse pointer is over the area of the collision shape of the object (in case the object has one), that is not the case in T2D, onMouseEnter() are always called when the mouse is anywhere over the whole object regardless of the collision shape. How can I achieve the same result of the legacy TGB?

I need to solve this because I have an overlapping objects in my scene (black lines) that have a collision shapes (red color) that do not overlap, I want the onMouseEnter() to be called only when the mouse is over one collision shape.

i43.tinypic.com/24osops.jpg

#1
09/29/2013 (2:45 pm)
You could use picking and change the pick mode to collision shapes. See the pickingToy for an example.
#2
09/30/2013 (3:42 am)
Thanks Mike, it worked like a charm.

If someone else needs the code:
function mySceneWindow::onTouchMoved(%this, %touchID, %worldPosition)
{
	%picked = myScene.pickPoint(%worldPosition, "", "", "collision");
	// in my setting, pickpoint() will always return a list of one object only 
    %obj=getWord(%picked, 0);
	if (isObject(%obj))
	{
		// remove highlight from the last picked object
		if (isObject($lastPickedObj)) $lastPickedObj.setBlendAlpha(0.5);
		// highlight the object or do what ever you want
		%obj.setBlendAlpha(1);
		$lastPickedObj=%obj;
	}
}