Game Development Community

dev|Pro Game Development Curriculum

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.

img832.imageshack.us/img832/5269/u7s.png
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.

imageshack.us/a/img543/6228/74zk.png

#1
07/09/2013 (3:57 am)
Thanks for the screenshots and update.

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?
#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
07/10/2013 (9:02 pm)
I've ported over the guiJoystick to a copy of the dev branch in
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.