Game Development Community

Mouse problem with multiple scenegraphs

by Nic Biondi · in Torque Game Builder · 06/30/2008 (9:26 pm) · 7 replies

I have a simple problem:

Quick explanation.
When I display an effect using a separate scenegraph on top of my normal scenegraph, it traps my mouse click.

Detail.
I created a new scenegraph which I use to put images on for an animation on top of my game screen. It works great but when I click on the screen to make my character jump by clicking in a direction it bugs out if the animation is running. It works just fine if there is no animation. But I setVisible(false) when there is no animation, so that no-doubt is the reason it doesn't trap the mouse when there is no animation.

Tried in vein:
I tried to set the scenewindow to not accept mouse calls but that doesn't seem to be enough. Anyone know if you can "pass though" the screen to get to the back scenegraph??

Alternatively this would work: if I could accept the mouse click without useing the "onMouseDown" command. Although I don't know if there is a way to accept the mouse in this way.

looking forward to your help.
cheers!
-nic

#1
07/01/2008 (12:49 pm)
The solution to this was floating around sometime last year. I know of three booleans dealing with the mouse that need to be false on your top layer.

lockMouse
useWIndowMouseEvents
useObjectMouseEvents

If this doesn't work, search TDN and this forum, I remember reading it last year.
#2
07/01/2008 (2:24 pm)
Cool thanks. I played with the useWindowMouseEvents. I think I also used some disable Mouse thing that didn't work. I'll poke around some more. thanks for replying!
#3
07/01/2008 (2:57 pm)
I assume what is happening here is you have two scene's, a foreground scene ($scene1) and a background scene ($scene2), and the only onMouseDown command that will work is $scene1.onMouseDown ? If this is the case, why don't you just throw the world position to the second scene ? For example, let's say you want to get the tile of the second scene when you mouse down. You need to trap the mouse down in the first scene, then do your processing in the second. If this is the case do something like:

$scene1::onMouseDown(%this, %modifier, %pos, %clicks)
{
   %scene2pos = $scene2.getMousePosition
   %scene2tilemap = $scene2graph.pickPoint(%scene2pos, BIT(%scene2tilemapgroup), BIT(%scene2tilemaplayer)
   %scene2layer = %scene2tilemap.getTileLayer(%activeLayer)
   %scene2tile = %scene2layer.pickTile(%scene2pos)
   echo(%scene2tile)
}

It means a bit more work passing things back and forth between layers but I think with something like the above you should be able to pull it off.
#4
07/01/2008 (9:42 pm)
Brilliant Glenn. Thanks-a-bunch!
Actually I don't care to much about the postition when I click. I do need to know the direction and distnace of the vector between the mouse and object, but I already have that drawn anyway. So using your insightful, and simple solution I simply trap the same event in each window as such:

function sceneW::onMouseDown(){
   playerJump();}
function topHudWindow::onMouseDown(){
   playerJump();}
function sceneWindow2D::onMouseDown(){
   playerJump();}

Works like a charm. One million points to glenn!
thanks all!
-nic
#5
07/01/2008 (10:21 pm)
Just be aware that unless you have three different objects that are using that function in the three different scene's you should only use the onMouseDown one you need. By that I mean if your player only exists in sceneWindow2D, that is the onMouseDown function you should be using. If you have three elements that need processing in each three scene's, then use the code you have provided.

Why ? Well essentially you are calling the playerJump function three times when you do an onMouseDown now.
#6
07/02/2008 (10:26 pm)
I learned from anouther forum you could use the profile "GuiModelessDialogProfile" on your overlapping scenewindow and it lets the mouse events right through.
#7
07/02/2008 (10:58 pm)
Ah, good to know; Something to put in the spank-bank, for sure.

While we are on the subject, refering to a previous post; I wanted to mention that my solution doesn't call the function more then once, even though each window accepts calls the same function. This is because the first scenewindow in the layer traps the click. I'm sure you were considering that would happen since your more complete solution uses pickPoint which would of course return the list of different objects collided.

toodles!
-nic