Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How can you make a hold-able down button? — Gideros Forum

How can you make a hold-able down button?

WickedWicked Member
edited February 2014 in Game & application design
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

  • You can use Button class which implements up and down state visuals of the button:
    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 :)
  • You can use Button class which implements up and down state visuals of the button:

    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 :)
    Thanks for the Help :)
    Also i might think about adding them to a single sprite object never though of that really , thanks again!
  • Just let me know if you get stucked, I'll post some more thorough examples ;)
  • Just let me know if you get stucked, I'll post some more thorough examples ;)
    I did manage to do it however , I managed to do it by using TOUCH_BEGIN and starting a timer and repeat the movement of the character and on TOUCH_END stop the timer but the example helped a lot thanks for the help :)
Sign In or Register to comment.