T2D GFX: Twinstick Action!
by Paul Jan · 07/08/2013 (3:11 am) · 3 comments
Unlike my previous resource for creating a iOS joystick, this time I've made a gui object that generates joystick inputs that react with the actionMap in the same way as a physical joystick.
While installing the windowManager systems for GFX, input got pretty much stomped, so creating an iOSInputManager to work with this was guilt-free.

Also cleaned up mounting gui objects to sceneobjects - things would get strange if the scenewindow camera is mounted to a sceneobject. I changed the position shift of the guiobject to occur at rendertime for the sceneobject.

While installing the windowManager systems for GFX, input got pretty much stomped, so creating an iOSInputManager to work with this was guilt-free.

if ( $platform $= "iOS" )
{
TruckToy.joystick1 = new GuiJoystickCtrl()
{
Profile = SandboxWindowProfile;
Position = "0 0";
Extent = "480 600";
};
TruckToy.joystick2 = new GuiJoystickCtrl()
{
Profile = SandboxWindowProfile;
Position = "0 0";
Extent = "480 600";
};
// Add it as a child window.
SandboxWindow.add( TruckToy.joystick1 );
SandboxWindow.add( TruckToy.joystick2 );
// Add window to the toy so it is destroyed.
TruckToy.add( TruckToy.joystick1 );
TruckToy.add( TruckToy.joystick2 );
%extent = SandboxWindow.getExtent();
TruckToy.joystick1.setExtent(%extent.x/2, %extent.y-40);
TruckToy.joystick1.Xevent = "xaxis";
TruckToy.joystick1.Yevent = "yaxis";
TruckToy.joystick1.CircleImage = "ToyAssets:Circle1";
TruckToy.joystick1.StickImage = "ToyAssets:Circle2";
TruckToy.joystick2.setExtent(%extent.x/2, %extent.y-40);
TruckToy.joystick2.setPosition(%extent.x/2, 0);
TruckToy.joystick2.Xevent = "zaxis";
TruckToy.joystick2.Yevent = "rzaxis";
TruckToy.joystick2.CircleImage = "ToyAssets:Circle1";
TruckToy.joystick2.StickImage = "ToyAssets:Circle2";
}Also cleaned up mounting gui objects to sceneobjects - things would get strange if the scenewindow camera is mounted to a sceneobject. I changed the position shift of the guiobject to occur at rendertime for the sceneobject.

About the author
#2
07/09/2013 (12:51 pm)
The guijoystickctrl can probably be brought over easily with a little work to the ios input implementation. Same with supporting joysticks on OSX.
#3
github.com/pchan126/Torque2D/tree/feature/guiJoystick
*fixed-ish* A bug that I've noticed on this branch is a tendency for the virtual joystick to "lock up" if the user touches outside the box and drags inside the box. There is a failure to pass along onMouseDragged events to the guiJoystick somewhere. I think its still a problem but I was making it worse by reducing the valid detection area in the inactive state.
07/10/2013 (9:02 pm)
I've ported over the guiJoystick to a copy of the dev branch ingithub.com/pchan126/Torque2D/tree/feature/guiJoystick
*fixed-ish* A bug that I've noticed on this branch is a tendency for the virtual joystick to "lock up" if the user touches outside the box and drags inside the box. There is a failure to pass along onMouseDragged events to the guiJoystick somewhere. I think its still a problem but I was making it worse by reducing the valid detection area in the inactive state.

Associate Mike Lilligreen
Retired T2Der
Are any of these fixes/improvements things that could be brought over to the current T2D branches or are they intertwined heavily with the GFX system?