I am trying to make a power button that when you tap it once, it starts a timer, and then when you tap it twice, it stops the timer and then correlates that time period with a power value.
I started off by creating a button that changes the location of text “JK” to make sure the tapping was working. I was also trying to print out the time difference between the first tap and the second tap, but the printout does not appear.
local textObject = display.newText(“JK”, 50, 50, nil, 24)
textObject: setTextColor(255, 255, 255)
local myButton =
display.newImage(“power-button-red-md2.png”)
myButton:scale(0.5, 0.5)
function myButton:tap (event)
textObject.x = math.random(0, display.stageWidth)
textObject.y = math.random(0, display.stageHeight)
end
myButton:addEventListener(“tap”, myButton)
myButton.markTime = system.getTimer()
– enterFrame listener function
local function trackTime(tap)
local secondsPassed = (tap.time - myButton.markTime) / 1000
if secondsPassed >= timeThresh then
display.newText( “You held down the button for at least " … timeThresh … " seconds.” )
Runtime:removeEventListener( “enterFrame”, trackTime )
end
end
I would appreciate some help.