--JPVirtualJoypad JPVirtualJoypad.activate ( sUserToken, sActivationKey ) JPVirtualJoypad.addButton ( hUser, sComponent, nOptJoypad, nOptButton ) JPVirtualJoypad.addUser ( hUser ) JPVirtualJoypad.removeAll ( ) JPVirtualJoypad.removeButton ( hUser, sComponent ) JPVirtualJoypad.removeStick ( hUser, sStickRootComponent ) JPVirtualJoypad.removeUser ( hUser ) JPVirtualJoypad.setEnabled ( hUser, bEnabled ) JPVirtualJoypad.addStick ( hUser, sStickRootComponent, nOptJoypad, nOptStick, bOptCenterUnderFinger, kOptBackVisibility, kOptThumbVisibility, nOptDirectionCount ) --Use this function to reference a virtual joypad stick. --sStickRootComponent is the tag of the component that contains can contain the stick thumb and the back of the stick. --The shape of sStickRootComponent defines the active area of the stick. --The tag of the thumb component must be sStickRootComponent.."Thumb" --The tag of the back component must be sStickRootComponent.."Back" --The shape of the back component defines the range of the stick. If there's no back component, the shape of the root component will be used instead. --Thanks to nOptDirectionCount, you can tell JPVirtualJoypad that the stick is limited, for instance, to 4 or 8 directions, like the directional arrows of the playstation gamepad. nAxisX, nAxisY = JPVirtualJoypad.transformStickValues ( nAxisX, nAxisY, nOptDeadZoneCoef, sOptCurve, vOptCurveParam0, vOptCurveParam1, vOptCurveParam2, vOptCurveParam3, vOptCurveParam4 ) --Call this function to transform the values you got with the onJoypadStickMove handler. --You can set a dead zone for the stick. --This function also allows you to apply a curve to the linear values passed to onJoypadStickMove. This feature requires JPTweener. --Constants JPVirtualJoypad.kVisibilityNever JPVirtualJoypad.kVisibilityAlways JPVirtualJoypad.kVisibilityWhenActive JPVirtualJoypad.kVisibilityWhenInactive --User notification events onJoypadButtonDown ( nJoypad, nButton ) onJoypadButtonUp ( nJoypad, nButton ) onJoypadStickDidBecomeActive ( nJoypad, nStick, sStickRootComponent ) onJoypadStickMove ( nJoypad, nStick, nAxisX, nAxisY ) onJoypadStickDidBecomeInactive ( nJoypad, nStick, sStickRootComponent ) --EXAMPLE --Create a HUD hierarchy like the following: |- MainHud.JoypadStick0 -- The tag you pass to JPVirtualJoypad.addStick. Its shape defines the area where the stick can become active. |- MainHud.JoypadStick0Back -- The tag of the back component must be the root component tag plus "Back". Its shape define the area of the thumb movement. |- MainHud.JoypadStick0Thumb -- The tag of the back component must be the root component tag plus "Thumb". |- MainHud.JoypadStick1 |- MainHud.JoypadStick1Back |- MainHud.JoypadStick1Thumb |- MainHud.JoypadButton0 |- MainHud.JoypadButton1 --A few calls to JPVirtualJoypad and you are done: JPVirtualJoypad.addStick ( hUser1, "MainHud.JoypadStick0", 0, 0, false, JPVirtualJoypad.kVisibilityAlways, JPVirtualJoypad.kVisibilityAlways ) JPVirtualJoypad.addStick ( hUser1, "MainHud.JoypadStick1", 0, 1, false, JPVirtualJoypad.kVisibilityWhenActive, JPVirtualJoypad.kVisibilityAlways ) JPVirtualJoypad.addButton ( hUser1, "MainHud.Button0", 0, 0 ) JPVirtualJoypad.addButton ( hUser1, "MainHud.Button1", 1, 1 )
JPVirtualJoypad is the easy way to get virtual joypads work in your game in no time. Provide to JPVirtualJoypad the graphics (HUD components) of your virtual joypad sticks/buttons and JPVirtualJoypad will do the logic for you.
Your virtual joypads will work just like a real joypad, and will send their values to the native onJoypadStickMove handler. This is the same with the virtual buttons and the onJoypadButtonDown/Up handlers.
JPVirtualJoypad will move your stick components, the only thing you have to do is to handle the values of the sticks. JPVirtualJoypad takes a few optional parameters. You can for instance set the visibility condition of the back and thumb textures of the stick. For instance the thumb could be visible only when the stick is not active and the thumb when it is active.
You can also tell JPVirtualJoypad that a stick must return values in a limited number of directions, for instance in 8 directions like the directional arrows of the playstation gamepad.
It also has an extra function, transformStickValues, that helps you apply a dead zone to the joypad stick values. Another great feature is the possibillity to use a tweener curve to the stick values. This way the stick values can be non linear when the stick moves. JPTweener is required for this feature.
The JPMultiTouch pack is required