Hi. I fear this will be the noob question #1 for the day, yet, as the title says,i’m having big troubles in finding a wayto temporarily remove a listener from a button.
Specifically, I need to limit the jump preventing the user to press the button again if the character hasn’t landed yet. I would need a way to disable the button after certain conditions are met (the user has lifted his finger or a certain amount of time has passed), and enable it again when the character lands again.
How would you do it? :x
Any advice\contribution would be really appreciated!
Here’s the code or, for those who may want it, the main file on dropbox: https://dl.dropbox.com/u/22024851/main.rar
[code]
local widget = require “widget”
local physics = require “physics”
physics.start();
physics.setDrawMode( “hybrid” )
pressbutton1 = false;
liftbutton1 = true;
–GROUND–
ground = display.newRect(0, 780, 1280, 5)
physics.addBody( ground, { density = 1, bounce=0 } )
ground.bodyType = “static”
–HERO–
hero = display.newRect(590, 500, 100, 100)
physics.addBody( hero, { density = 0.1, bounce=0 } )
hero.bodyType = “dynamic”
hero.isFixedRotation = true
–BUTTONS–
upbutton = display.newRect(10, 600, 150, 150)
downbutton = display.newRect(1120, 600, 150, 150)
–BUTTON1EVENT–
function button1event( event )
if event.phase == “began” then
pressbutton1 = true;
liftbutton1 = false;
–print(“button1pressed”)
elseif event.phase == “ended” then
pressbutton1 = false;
liftbutton1 = true;
–print(“button1lifted”)
end
end
–JUMPFUNCTION–
function jumping()
if pressbutton1 then
print(“button1beingpressed”)
hero:applyForce ( 0, -70)
end
end
–UPDATESTAGEFUNCTION + LISTENERS AND STUFF–
local function updatestage( event )
jumping()
end
timer.performWithDelay(1, updatestage, -1)
upbutton:addEventListener( “touch”, button1event, 1)
--------------------------------------------- [import]uid: 173509 topic_id: 30628 reply_id: 330628[/import]
[import]uid: 62706 topic_id: 30628 reply_id: 122723[/import]