Difference between revisions of "TntVirtualPad"

Line 69: Line 69:
 
[[CTNTVirtualPad:setHideDelay]] ''sets the VPAD hide delay''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setHideDelay(msDelay) sets the VPAD hide delay-->
 
[[CTNTVirtualPad:setHideDelay]] ''sets the VPAD hide delay''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setHideDelay(msDelay) sets the VPAD hide delay-->
 
[[CTNTVirtualPad:setHideMode]] ''sets the VPAD hide mode''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setHideMode(hideMode) sets the VPAD hide mode-->
 
[[CTNTVirtualPad:setHideMode]] ''sets the VPAD hide mode''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setHideMode(hideMode) sets the VPAD hide mode-->
[[CTNTVirtualPad:setJoyAsAnalog]] ''sets VPAD joystick analog mode''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setJoyAsAnalog(padComponent, isAnalogic) sets VPAD joystick analog mode-->
+
[[CTNTVirtualPad:setJoyAsAnalog]] ''sets VPAD joysticks analog mode''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setJoyAsAnalog(padComponent, isAnalogic) sets VPAD joysticks analog mode-->
 +
[[CTNTVirtualPad:setJoyStyle]] ''sets VPAD joysticks movement style''<br/><!-- GIDEROSMTD:CTNTVirtualPad:setJoyStyle(padComponent, style) sets VPAD joysticks movement style-->
 
[[CTNTVirtualPad:start]] ''starts the VPAD''<br/><!-- GIDEROSMTD:CTNTVirtualPad:start() starts the VPAD-->
 
[[CTNTVirtualPad:start]] ''starts the VPAD''<br/><!-- GIDEROSMTD:CTNTVirtualPad:start() starts the VPAD-->
  
Line 100: Line 101:
 
[[PAD.STICK_SINGLE]]<br/><!-- GIDEROSCST:PAD.STICK_SINGLE 1-->
 
[[PAD.STICK_SINGLE]]<br/><!-- GIDEROSCST:PAD.STICK_SINGLE 1-->
 
[[PAD.STICK_DOUBLE]]<br/><!-- GIDEROSCST:PAD.STICK_DOUBLE 2-->
 
[[PAD.STICK_DOUBLE]]<br/><!-- GIDEROSCST:PAD.STICK_DOUBLE 2-->
 +
 +
[[PAD.STYLE_CLASSIC]]<br/><!-- GIDEROSCST:PAD.STYLE_CLASSIC 10-->
 +
[[PAD.STYLE_MOVABLE]]<br/><!-- GIDEROSCST:PAD.STYLE_MOVABLE 11-->
 +
[[PAD.STYLE_FOLLOW]]<br/><!-- GIDEROSCST:PAD.STYLE_FOLLOW 12-->
 
|}
 
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Revision as of 13:43, 3 December 2020

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2019.4

Description

Adds a virtual pad to your game/app screen.

You can find the graphics for the pads and the text file that comes with it:

TNTVirtualPad.png

Examples

Add a virtual pad to your scene

require "tntvirtualpad"

LevelX = Core.class(Sprite)

function LevelX:init()
	-- bg
	application:setBackgroundColor(0x0099a0)
	-- tnt virtual pad
	local texturevpad = TexturePack.new("gfx/UI/TNTVirtualPad.txt", "gfx/UI/TNTVirtualPadX.png", true)
	self.vPad = CTNTVirtualPad.new(self, texturevpad, PAD.STICK_SINGLE, PAD.BUTTONS_ONE, 100, 0)
	self.vPad:setJoyStyle(PAD.COMPO_LEFTPAD, PAD.STYLE_FOLLOW)
	self.vPad:setScale(PAD.COMPO_LEFTPAD, 1)
	self.vPad:setScale(PAD.COMPO_BUTTON1, 1)
	self.vPad:setHideDelay(5000)
	self.vPad:start()
	-- tnt virtual pad listeners
	self.vPad:addEventListener(PAD.LEFTPAD_EVENT, self.onVKeyDown, self)
	self.vPad:addEventListener(PAD.BUTTON1_EVENT, self.vShoot, self)
end

-- VIRTUAL PAD HANDLER
function LevelX:onVKeyDown(event)
	print(event.data.power)
	print(event.data.angle)
	print(math.cos(event.data.angle))
	print(math.sin(event.data.angle))
	-- example usage
	--self.player.posx += self.player.vx * math.cos(event.data.angle)
	--self.player.posy += self.player.vy * math.sin(event.data.angle)
	--if math.cos(event.data.angle) < 0 then self.player:setSkew(5, -5)
	--elseif math.cos(event.data.angle) > 0 then self.player:setSkew(-5, 5)
	--else self.player:setSkew(0, 0)
	--end
end

function LevelX:vShoot(event)
	if event.data.state == PAD.STATE_BEGIN then
		-- example usage
		--local missile = Missiles.new(self.player.posx, self.player.posy - 12)
		--table.insert(self.missiles_list, missile)
	end
end

Methods

CTNTVirtualPad.new creates a new VPAD object class

CTNTVirtualPad:free frees the VPAD
CTNTVirtualPad:setAlpha sets the VPAD alphas
CTNTVirtualPad:setColor sets the VPAD color
CTNTVirtualPad:setHideDelay sets the VPAD hide delay
CTNTVirtualPad:setHideMode sets the VPAD hide mode
CTNTVirtualPad:setJoyAsAnalog sets VPAD joysticks analog mode
CTNTVirtualPad:setJoyStyle sets VPAD joysticks movement style
CTNTVirtualPad:start starts the VPAD

Events

Constants

PAD.BUTTONS_NONE
PAD.BUTTONS_ONE
PAD.BUTTONS_TWO
PAD.BUTTONS_THREE
PAD.BUTTONS_FOUR
PAD.BUTTONS_FIVE
PAD.BUTTONS_SIX

PAD.COMPO_BUTTON1
PAD.COMPO_BUTTON2
PAD.COMPO_BUTTON3
PAD.COMPO_BUTTON4
PAD.COMPO_BUTTON5
PAD.COMPO_BUTTON6
PAD.COMPO_LEFTPAD
PAD.COMPO_RIGHTPAD

PAD.MODE_NOHIDE
PAD.MODE_GHOST
PAD.MODE_HIDDEN

PAD.STICK_NONE
PAD.STICK_SINGLE
PAD.STICK_DOUBLE

PAD.STYLE_CLASSIC
PAD.STYLE_MOVABLE
PAD.STYLE_FOLLOW