Game Development Community

OnMouseDown() layer priotities

by Hamish Fawns · in Torque Game Builder · 07/23/2008 (12:02 am) · 2 replies

When two sprites are overlapping is there any way to only have onMouseDown() called on the object in the lower layer (the one on top)? It's a huge problem for me when I try to click a sprite and all the sprites underneath get the onMouseDown() message as well. I still want to be able to click the higher layer sprites when not covered by the lower layer sprite.

#1
07/23/2008 (12:21 am)
Try this:

function t2dSceneWindow::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
    // Find all of the objects at this point
    %pickList  = %this.getSceneGraph().pickPoint(%worldPosition);
    %pickCount = getWordCount(%pickList);
    for (%i = 0; %i < %pickCount; %i++)
    {
        %pickObject = getWord(%pickList, %i);
        if (!isObject(%minObject) || %pickObject.getLayer() < %minObject.getLayer())
            %minObject = %pickObject;
    }
    
    // We didn't have an object at that point so just return
    if (!isObject(%minObject))
        return;
    
    // Run the method that you want to
    %minObject.myMethod();
}

Rather than all of your objects in the scene allowing mouse events, only the t2dSceneWindow should have them enabled.
#2
07/23/2008 (4:04 am)
Thanks. I'll give that a try. I also noticed the function setObjectMouseEventInvisibleFilter(bool useInvisible). Is this supposed to stop hidden sprites from receiving mouse events? I tried using this (setting it to false) but it didn't make any difference.