Hello Everyone,
From the below you can see I have created a dpad sort of system in which you tap the buttons in order to move however at this point in time when you tap them the command will only execute once where as i want it to keep executing over and over until the user lifts their finger how would i do this?
Btw I am sorta new to this framework and coding language and so sorry if it is obvious
Thanks in advance
Wicked
Current code for DPAD:
local function Dpad(event)
uparrow = Bitmap.new(Texture.new("images/uparrow.png"))
uparrow:setAnchorPoint(0.5,0.5)
uparrow.x, uparrow.y = 150,360
uparrow:setPosition(uparrow.x, uparrow.y)
stage:addChild(uparrow)
rightarrow = Bitmap.new(Texture.new("images/rightarrow.png"))
rightarrow:setAnchorPoint(0.5,0.5)
rightarrow.x, rightarrow.y = 190,400
rightarrow:setPosition(rightarrow.x, rightarrow.y)
stage:addChild(rightarrow)
leftarrow = Bitmap.new(Texture.new("images/leftarrow.png"))
leftarrow:setAnchorPoint(0.5,0.5)
leftarrow.x, leftarrow.y = 110,400
leftarrow:setPosition(leftarrow.x, leftarrow.y)
stage:addChild(leftarrow)
downarrow = Bitmap.new(Texture.new("images/downarrow.png"))
downarrow :setAnchorPoint(0.5,0.5)
downarrow .x, downarrow .y = 150,440
downarrow :setPosition(downarrow .x, downarrow .y)
stage:addChild(downarrow)
downarrow:addEventListener(Event.TOUCHES_BEGIN, MoveD, downarrow)
uparrow:addEventListener(Event.TOUCHES_BEGIN, Move, uparrow)
rightarrow:addEventListener(Event.TOUCHES_BEGIN, MoveR, rightarrow)
leftarrow:addEventListener(Event.TOUCHES_BEGIN, MoveL, leftarrow)
end
Comments
https://github.com/gideros/Button/blob/master/button.lua
Inside the state update you can implement a Timer, which starts at button down (button pressed) state and stops at button up state (button released)
Additional suggestin, you can add all your up/down/left/right buttons to one single Sprite object and then add this sprite to the stage/scene.
This way you will be able to move the whole group of buttons by simple changing position of this parent sprite
Also i might think about adding them to a single sprite object never though of that really , thanks again!