onMouseDown problems - different behavior in TGE and TGEA?
by Ingo Seidel · in Torque Game Engine Advanced · 04/07/2009 (8:38 am) · 4 replies
Hi,
I have ported a project from TGE to TGEA and everything is functioning apart from the onMouseDown behavior on the player interface. In my application, the mouse cursor is displayed at all times and the player is able to click on other players (I am using the 3d object selection resource for this). In order to intercept the mouse click from the player I had defined the following script code in my TGE project:
This worked perfectly with TGE and the method was called whenever the mouse was clicked by the player. However, in TGEA this function simply does not get called anymore. Instead, the empty onMouseDown function in the GuiControl class is called. I have tried to find any differences between the TGE and TGEA GuiControl code, but could not find any so far. Has anyone an idea why the overloading does not work anymore? Has something changed in TGEA?
thanks & best regards
I have ported a project from TGE to TGEA and everything is functioning apart from the onMouseDown behavior on the player interface. In my application, the mouse cursor is displayed at all times and the player is able to click on other players (I am using the 3d object selection resource for this). In order to intercept the mouse click from the player I had defined the following script code in my TGE project:
function PlayGui::onMouseDown(%this)
{
...
}This worked perfectly with TGE and the method was called whenever the mouse was clicked by the player. However, in TGEA this function simply does not get called anymore. Instead, the empty onMouseDown function in the GuiControl class is called. I have tried to find any differences between the TGE and TGEA GuiControl code, but could not find any so far. Has anyone an idea why the overloading does not work anymore? Has something changed in TGEA?
thanks & best regards
#2
I didn't know of this binding method with "button0" and I tried it out instantely. However, it appears that the handler will only be called when the mouse cursor is turned off. But I need it to be called when the mouse cursor is turned on.
I haven't tried the second solution, but it would probably work. However, I was in the opinion that a method could be overwritten in script for a specific object, like PlayGui::onMouseDown above. This worked perfectly in TGE; is it no longer possible in TGEA?
04/07/2009 (9:57 am)
Wow that was fast.I didn't know of this binding method with "button0" and I tried it out instantely. However, it appears that the handler will only be called when the mouse cursor is turned off. But I need it to be called when the mouse cursor is turned on.
I haven't tried the second solution, but it would probably work. However, I was in the opinion that a method could be overwritten in script for a specific object, like PlayGui::onMouseDown above. This worked perfectly in TGE; is it no longer possible in TGEA?
#3
I'm pretty sure there has never been any kind of automatic overriding of methods like you may be thinking, the script methods have to be called somehow from code, or passed along from other script methods.
I just did some looking and noticed that there is a GuiMouseEventCtrl class in both TGEA and TGE 1.4.2 with an onMouseDown handler that calls out to an onMouseDown script callback using pretty much the same method that I described. So possibly your PlayGui is using that control in some way, or was otherwise modified to pass the mouse commands on to script.
04/07/2009 (11:05 am)
Ingo,I'm pretty sure there has never been any kind of automatic overriding of methods like you may be thinking, the script methods have to be called somehow from code, or passed along from other script methods.
I just did some looking and noticed that there is a GuiMouseEventCtrl class in both TGEA and TGE 1.4.2 with an onMouseDown handler that calls out to an onMouseDown script callback using pretty much the same method that I described. So possibly your PlayGui is using that control in some way, or was otherwise modified to pass the mouse commands on to script.
#4
04/08/2009 (12:18 am)
Damn, it was totally my fault, I had added some code to the GameTSCtrl which I had not ported to the new code base. This code was overriding the onMouseDown method. Anyway, thanks for your comments that helped me track down the issue.
Torque Owner Gerald Fishel
Development Ninja
If you look at the default playGui.cs and default.bind.cs you'll see the PlayGui uses an ActionMap named "moveMap", and you setup a mouse click handler like this:
Alternatively you could add code in the GuiControl::onMouseDown method to call onMouseDown method defined in script. i.e. something like this:
SimObjectId objId = getId(); if( isMethod( "onMouseDown" ) ) { Con::executef(this, "onMouseDown", Con::getIntArg(objId)); }I haven't tested it, but if your mouse click is being kicked up to GuiControl::onMouseDown, then that should call your PlayGui::onMouseDown method.