JPButton

JPButton

Significantly improves the HUD buttons default behavior
Version : 3.0
Price : $20
State : Out

Changelog

v3.0

  • Now compatible with ShiVa 2.0.
  • Plugin API compiled for Mac and Linux in addition to Windows : it will provide API completion in the Script module in ShiVa Editor for each of these operating systems.
  • Now uses a user token instead of an email to activate

v2.1

  • Added function removeUser ( hUser )

v2.0

  • Compatible with multiple local users

v1.6

  • Optimized for ShiVa 1.9.2

v1.5

  • Fixed a bug when picking a component with no tag
  • Fixed a bug when calling an action with no tag

v1.4

  • It is now possible to use a 'sensor' to extend the area of effect of a button. This sensor must be a button named like the real button plus "sensor". If my button is "MyHud.myButton", the button sensor must be named "MyHud.myButton_sensor_"
  • Fixed an issue with multitouch

v1.3

  • Internal modifications to prevent eventual conflicts between packs.

v1.2

  • Fixed a random issue blocking the activation of the pack

v1.1

  • Error messages now are easier to understand.

API

--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 )

Description

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!