0
votes
local held = false

local function jumperTap ()

    jumper:applyForce( 0, 200, jumper.x, jumper.y )
    return false

end

Runtime:addEventListener( "tap", jumperTap )


local function holdListener(event)

    held = true
    jumper:applyForce( 0, 250, jumper.x, jumper.y  )
    return true

end




local function jumperTouch(event)

    if (event.phase == "began") then
        display.getCurrentStage():setFocus(jumper)
        holdTimer = timer.performWithDelay( 500, holdListener )
    elseif (event.phase == "moved") then
        timer.cancel(holdTimer)
    elseif (event.phase == "ended" or event.phase == "cancelled") then
        display.getCurrentStage():setFocus(nil)
        timer.cancel(holdTimer)
        held = false
    end

end

Runtime:addEventListener( "touch", jumperTouch )

I'm trying to have a tap and a touch and hold. When the touch and hold happens, the jumper will have more force applied to him so he can jump higher when the screen is touched and held. When the screen is tapped, he will have a shorter jump.

When I tap, the expected thing happens. When I tap and hold, the expected thing happens. I do have a few glaring issues though due to my novice-ness in Corona. They are...

- When I tap and hold, all goes well, but when I release, it glitches and what is performed is what seems to be a the tap event. Not sure why this is happening

- When I perform the tap event, I am able to perform it again while the object is in the air--this brings him down to the ground and the tap event seems to be performed again, but with less force.

Any and all help is greatly appreciated!

EDIT: I put return true and return false in just to try something different, but it didn't affect anything.

1

1 Answers

0
votes

I recommend testing out a debounce in order to prevent the tap/tap+hold events from doubling up. By passing the functions through a global boolean you can make it so they can only tap while no tap events are occuring. Because based on your events it seems they happen regardless if they are currently in 'jump' mode or not.

Example:

debounce = false

function func1()
   if debounce == false then
      debounce = true
      //event script
   end
end

function event_ended()
   debounce = false
end