Game Development Community

Getting MouseDown on TopMost Object Only?

by Amjad Yahya · in Torque 2D Beginner · 06/21/2013 (6:51 am) · 4 replies

When 2 objects overlap and you click the mouse over them you get onMouseDown callbacks for both of them, I want to be able to handle the topmost object callback only. This was an issue back in TGB and it seems that it have not been addressed in T2D 2.0, I recall in TGB someone did post a very good solution to this issue that involves calling t2dSceneGraph::onUpdateSceneTick() callback. This call back does not exist anymore, so I wonder what is the alternative in T2D 2.0.


#1
06/21/2013 (7:42 am)
Since the onUpdateSceneTick is just checking the $mouseDownEaten variable (referencing the post that you linked), why not just create a recursive schedule check such as follows:

function updateSceneTick() {
    cancel($sceneTicker);
    if ($mouseDownEaten) {
       // do stuff because the mouse is set
    } 
    $sceneTicker = schedule(10, 0, updateSceneTick); // update it every 10 milliseconds
}

Then just call that function once somewhere to activate it. You can stop the tick by just using:

cancel($sceneTicker);

Hope this helps :)
#2
06/21/2013 (10:45 am)
Thanks Jeff, you've been so helpful. Though, I still want to know if there is an alternative to t2dSceneGraph::onUpdateSceneTick() callback!
#3
06/22/2013 (8:48 am)
The callbacks were renamed to be something more sensible and less obscure. Why not try looking at the source itself, it's pretty simple to search for stuff like "OnXXXXXX". The callbacks are issued with a command like "Con::execute....."

Anyway, try:

Scene::OnSceneUpdate() - Each physics tick (1/60th sec)
Scene::OnSceneRender() - Each frame.
#4
06/22/2013 (9:55 am)
Thanks Alien Cabbage, That's what I was looking for.

It would be helpful if all callbacks get documented.