Bug in Torque? Mouse cursor not being reset properly in Mac fullscreen mode.
by Nate Gertsch · in Torque Game Builder · 09/18/2009 (9:06 pm) · 8 replies
Hello everyone,
I've run across a strange bug and I was wondering if anyone had run across the same issue and created a fix or found a work around. I have a game where the player controls his objects by moving the mouse. Since I don't want him to hit the boundaries of the game area, I hide the cursor and reset it to 0,0 every time I detect movement. The code works fine on Mac windowed mode but when I go to full screen, the cursor won't reset.
To reproduce this bug, open up a project in fullscreen mode and move the cursor around. Then type sceneWindow.setMousePosition("0 0") and observe that while the cursor appears to move back to the center, if you move the mouse again it snaps back to where it was before. Then open the same project in windowed mode and you'll see the mouse go the center and stay there when you go through the same steps.
There were some people who were having similar issues with custom cursors here: www.garagegames.com/community/forums/viewthread/72189 but I want to adjust the position of my current cursor not create a new one like they are trying to do. Has anyone run into this issue before and resolved it successfully?
I've run across a strange bug and I was wondering if anyone had run across the same issue and created a fix or found a work around. I have a game where the player controls his objects by moving the mouse. Since I don't want him to hit the boundaries of the game area, I hide the cursor and reset it to 0,0 every time I detect movement. The code works fine on Mac windowed mode but when I go to full screen, the cursor won't reset.
To reproduce this bug, open up a project in fullscreen mode and move the cursor around. Then type sceneWindow.setMousePosition("0 0") and observe that while the cursor appears to move back to the center, if you move the mouse again it snaps back to where it was before. Then open the same project in windowed mode and you'll see the mouse go the center and stay there when you go through the same steps.
There were some people who were having similar issues with custom cursors here: www.garagegames.com/community/forums/viewthread/72189 but I want to adjust the position of my current cursor not create a new one like they are trying to do. Has anyone run into this issue before and resolved it successfully?
#2
09/19/2009 (3:55 pm)
Open up CommonConfig.xml under the common folder in your project and change the full screen setting from False to True.
#3
09/19/2009 (4:04 pm)
Thanks But I changed it to True but when I play the scene its still the size as before.
#4
Anyone have any ideas about the mouse not resetting in full screen mode on the mac? I could go without the resetting to the center but eventually the user cursor gets to the side and the player can't move in that direction anymore.
09/21/2009 (2:59 pm)
You're probably running the game through the builder interface while I'm at the point where I'm modifying script files and running the game through xcode as I don't need to make any changes to the levels. I recall that the builder liked to overwrite the preferences in the commmonconfig.xml when you run the game through the run game button. There's probably a setting in TGB that sets full game but I don't know where.Anyone have any ideas about the mouse not resetting in full screen mode on the mac? I could go without the resetting to the center but eventually the user cursor gets to the side and the player can't move in that direction anymore.
#5
09/21/2009 (3:24 pm)
Also using toggleFullscreen() should allow you to go from windowed to fullscreen mode in the middle of the game.
#6
09/21/2009 (5:00 pm)
Here is a better description of the problem provided by Kalle Wik about a year ago. www.garagegames.com/community/forums/viewthread/67835/2#comments It would be nice to get a response a GG employee to know if this bug is in their database and if anyone ever came up with a fix. This is not an obscure issue as it involves a common function in TGB being used on a relatively common OS operating on a common setting.Quote:
Found a cursor-related bug only on Mac OS X, and only if TGB is running fullscreen. It's breaking a game in development and we have to fix it.
Steps to repro:
1. Build out a new, empty game in TGB 1.7.4 on Mac OS X
2. Set the game to fullscreen using Canvas.pushDialog(OptionsDlg); from console window
3. Do a sceneWindow2D.setMousePosition(0,0) and YES the cursor moves there
4. Move the mouse, it snaps back to the position it had been at before!
As mentioned this is breaking a game at "ready to ship" level, and we're very interested to get a fix! Doesn't happen in windowed mode, just fullscreen, and only Mac OSX. Has been a problem in TGB 1.7.2 as well.
Note: we have the source and commercial package, and will be happy to compile in a fix! Suggestions much appreciated.
#7
On the plus side, I've made my first modification to the TGB source code. I feel like I've crossed a line or something.
09/21/2009 (8:12 pm)
Ok, I solved it but I'm too tired to go into the details right now. It involved modifying the engine following the some code I read on a old post in the TGEA forum. I'll post a link to that post and step by step instructions of what I did so that some poor person doesn't have to go and figure this out himself. Better yet, I hope some GG employee reads this and incorporates the fix into the next version of TGB.On the plus side, I've made my first modification to the TGB source code. I feel like I've crossed a line or something.
#8
1) Open macCarbInput.cc under platform/PlatformMacCarb
2) Replace Input::setCursorPos with the following code
3) Go to guiCanvas.h and add the follow in the include statements if it isn't there already.
That's all that was necessary for me to get setPosition to work. There were other changes in the post that were either implemented or didn't work at all but these changes allow me to get my game up and working properly.
09/22/2009 (2:44 pm)
Here is the post that pushed me in the right direction. www.garagegames.com/community/forums/viewthread/19875/ It discribes the problem and implements a fix for it. Now if you're running TGB 1.7.4 or later, most of this fix is already implemented in the your current version. However some part of it doesn't work for the Mac full screen mode and you'll need to modify part of the mac input. I'm not exactly sure why this works as I'm following the code of one of the posters in the thread and if anyone wants to explain it, they are most welcome.1) Open macCarbInput.cc under platform/PlatformMacCarb
2) Replace Input::setCursorPos with the following code
void Input::setCursorPos(S32 x, S32 y)
{
Rect r;
Point targetPoint;
GrafPtr savePort;
// get the center of the window
if (platState.appWindow )
{
GetWindowBounds(platState.appWindow, kWindowContentRgn, &r);
targetPoint.h = r.left + x;
targetPoint.v = r.top + y;
} else {
targetPoint.h = x;
targetPoint.v = y;
}
CGDirectDisplayID displayID = platState.cgDisplay;
CGRect bounds = CGDisplayBounds(displayID);
CGPoint cgWndCenter;
cgWndCenter.x = targetPoint.h + bounds.origin.x;
cgWndCenter.y = targetPoint.v + bounds.origin.y;
CGSetLocalEventsSuppressionInterval(0);
CGDisplayMoveCursorToPoint(displayID, cgWndCenter);
CGSetLocalEventsSuppressionInterval(0.25);
}3) Go to guiCanvas.h and add the follow in the include statements if it isn't there already.
#ifndef _PLATFORMINPUT_H_ #include "platform/platformInput.h" #endif
That's all that was necessary for me to get setPosition to work. There were other changes in the post that were either implemented or didn't work at all but these changes allow me to get my game up and working properly.
Torque Owner Robert Carroll