Difference between revisions of "CTNTVirtualPad.Event"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
Line 32: Line 32:
 
=== Example ===
 
=== Example ===
 
'''Same as front Virtual Pad page but shortened'''
 
'''Same as front Virtual Pad page but shortened'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
require "tntvirtualpad"
 
require "tntvirtualpad"
  

Revision as of 14:26, 13 July 2023

Available since: Gideros 2019.4
Class: VirtualPad

Description

Those are all the Events dispatched by the TNT Virtual Pad components.

The events hold a data table containing useful information.

Joystick Events

  • PAD.LEFTPAD_EVENT
  • PAD.RIGHTPAD_EVENT

Joysticks Event data table:

  • data.selected can be true or false (true when element is interacting with user)
  • data.power value (float) from 0 to 1 (1 when stick is on the base border)
  • data.angle angle of joystick in radians. If joystick is set as digital, values are from 0 to 7 (0 is right and so on in clockwise order, steps are 45 degrees)
  • data.state is the state of the joystick. It returns PAD.STATE_NONE→joystick not pressed, PAD.STATE_BEGIN→joystick begin touch, PAD.STATE_DOWN→joystick touched and pressed, PAD.STATE_END→joystick begin release

Buttons Events

  • PAD.BUTTON1_EVENT
  • PAD.BUTTON2_EVENT
  • PAD.BUTTON3_EVENT
  • PAD.BUTTON4_EVENT
  • PAD.BUTTON5_EVENT
  • PAD.BUTTON6_EVENT

Buttons Event data table:

  • data.selected can be true or false (true when element is interacting with user)
  • data.state is the state of the button. It returns PAD.STATE_NONE→button not pressed, PAD.STATE_BEGIN→button begin touch, PAD.STATE_DOWN→button touched and pressed, PAD.STATE_END→button begin release

Example

Same as front Virtual Pad page but shortened <syntaxhighlight lang="lua"> require "tntvirtualpad"

LevelX = Core.class(Sprite)

function LevelX:init() -- tnt virtual pad listeners self.vPad:addEventListener(PAD.LEFTPAD_EVENT, self.onVKeyDown, self) self.vPad:addEventListener(PAD.BUTTON1_EVENT, self.vShoot, self) end

function LevelX:onVKeyDown(event) print(event.data.power) print(event.data.angle) end

function LevelX:vShoot(event) if event.data.state == PAD.STATE_BEGIN then --local missile = Missiles.new(self.player.posx, self.player.posy - 12) end end </source>