--JPButton API JPButton.activate ( sUserToken, sActivationKey ) JPButton.enableMultiTouch ( bEnabled ) JPButton.setButtonMoveTolerance ( nButtonMoveTolerance ) JPButton.setButtonShapeExtraSize ( nButtonShapeExtraSize ) JPButton.addUser ( hUser ) JPButton.removeUser ( hUser ) --User notification events: "onButtonDidEnterNormalState" ( sButton ) "onButtonDidEnterPressedState" ( sButton )
JPButton replaces the default ShiVa behavior for "onClicked" event of HUD buttons which stupidly trigger the event when the user's finger (or mouse) is released over the button.
JPButton will inform you in real time when the button state changes: normal or pressed state. When the user places his finger on a button, it enters the state "pressed". Now if, without releasing his finger, the user moves his finger on the screen farther or closer to the button, it will switch between "normal" and "pressed" states according to distance between the finger and the button's area.
JPButton does much more: it also checks if the button has not been moved, for example if it is present in a list, in order not to trigger the event if it was moved because of the list scrolling causing the button to remain under the user's finger.
All this is automatic, the event is triggered by JPButton. All you have to do (if you want to) is to implement the "onButtonDidEnterNormalState" and "onButtonDidEnterPressedState" handlers in order to animate your buttons, for example by changing their color to make them darker when pressed. Even better, you can use it with JPSprite to set a specific sprite for each of the button states:
function MyAIModel.onButtonDidEnterNormalState ( sButton ) JPSprite.setComponentSprite ( sButton, "button_normal_sprite" ) end function MyAIModel.onButtonDidEnterPressedState ( sButton ) JPSprite.setComponentSprite ( sButton, "button_pressed_sprite" ) end
JPButton also allows you to enlarge the area of effect of your buttons, which is very convenient for small buttons (or for the large fingers...).
But wait, that's not all, by combining JPButton with JPMultitouch, you provide to your HUD buttons the possibility to be used in multitouch, I mean you will be able to click on several buttons at once. Very convenient for games using a virtual game pad, for instance! There's nothing else to do than to add these 2 packs to your game and call JPButton.enableMultitouch ( true ) and it will work like a charm!