Game Development Community

Mouse Click on Scene

by Jason Darby · in Torque Game Builder · 08/30/2009 (2:43 pm) · 3 replies


I can initiate a move between scenes using an object, but I am wondering how i do this at the scene level. This does raise a bigger question for me, which is how to initiate things at the scene rather than object level.

Ive enabled mouse events in the Game.cs file.

%this.setUseMouseEvents( true );

So how would i check to move to the next screen in a particular scene.

I created a CS file (which is exec in the main file) with the following code:

function screenmmove::OnMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
// Go to Screen Paris
sceneWindow2D.loadLevel("game/data/levels/Paris.t2d");
}

I then called the screenmove function by specifying it in the properties sheet.. but this does not work... what am i doing wrong, and also what is the recommended method for calling things at the scene level rather than the object level.

Also it raises another question of using the "Use Mouse Events" on objects... of course this isnt an object but the who scene. So DO i have to use it on an object?

Sorry for the confusing post.

Thanks

About the author

Computer games book author, have written 6 game creation books, published by Cengage Course Technology. Owner of Arcade website www.madword.com and Castle software.


#1
08/30/2009 (6:55 pm)
I can give some general guidelines, but I'd need more information to answer your specific question.

First, using "%this.setUseMouseEvents(true);" won't make mouse events work on the window. You need to look in game/gui/mainScreen.gui and check that the sceneWindow2D has the following line: "useWindowMouseEvents = 1;".

Then the function you need to implement is:
function sceneWindow2D::onMouseDown( %this, %modifier, %worldPosition, %mouseClicks )
{
  sceneWindow2D.loadLevel( "game/data/levels/Paris.t2d" );
  // You could also use %this.loadLevel( ... );
}

I'm not sure what you mean by the "properties sheet". But the code above will be called as soon as you click the mouse.
#2
08/31/2009 (7:49 am)
OK, lets try and make this clearer :) Take the scenario where I have two levels. Of these two levels I want to detect mouse events but only for the second level. Am I right in thinking that the application only ever has one 'sceneWindow2D'? If so enabling mouse events would also mean my application can detect mouse events on my first level. If not can you please advise how to go about it.

Thanks
#3
08/31/2009 (12:56 pm)
Yep... in general, there's only the one sceneWindow2D.

You can go into the mainScreen.gui and set the "useWindowMouseEvents" to 0. Then, when you load your second level, simply put the following line after your "loadLevel":

sceneWindow2D.loadLevel( ... );
  sceneWindow2D.useWindowMouseEvents = 1;