So my game just uses touch to trigger a jump.
I’m thinking of doing a hold screen to make the character duck under objects
So I think I need to start with a touch began statement calculate past two frames so that he ducks during that hold. Then when there’s a touch end he doesn’t jump.
Does that sound right?
measure the time t of hold, and if t > t_hold, then duck and do not jump.
Awesome thank you @Jmv38 !
My code isn’t working because I’m using a timer = timer+1 and it’s resetting. I think I need to use a delta timer instead to calculate the hold…
@Majormorgan Here’s an example. I didn’t add jump or duck code so I just move the sprite up or down to show jump or duck. You can add you’re own jump/duck code. Tap screen to jump. Tap and hold for greater than .2 seconds to duck.
text("tap screen to jump",WIDTH/2,HEIGHT-100)
text("hold screen for .2 sec then release to duck",WIDTH/2,HEIGHT-150)
sprite("Planet Cute:Character Boy",WIDTH/2,dy)
if tmr>=0 then
tmr=tmr+DeltaTime -- add to timer
if jump then -- perform jump code
if duck then -- perform duck code
if t.state==BEGAN then
tmr=0 -- reset timer
if t.state==ENDED then
duck=false -- reset variables
if tmr>delay then -- timer greater than delay count
duck=true -- set duck
jump=true -- set jump
The user and all related content has been deleted.
Hey @dave1707 they are both cool examples and the swipe up and swipe down could be an even better answer! I’m coding In your timed approach above for the hold approach. I’ve got the less than tmr delay working. Still not cracked the hold part yet, but I’m almost there. I have to modify you code because of the engine I built is different.
Your ideas are really cool. I’ll post when I have it working
Thank you so much!
@Majormorgan This isn’t the hold screen or tap screen, but a flick in an up or down direction to jump or duck. With a flick up or down, there isn’t the delay to determine if the touch is being held to cause the duck. Also, there isn’t a need for a timer.
background(40, 40, 50)
text("flick up to jump, down to duck",WIDTH/2,HEIGHT-100)
if cb.x<50 or cb.x>WIDTH-50 then -- keep sprite on the screen
cb.x=cb.x+val -- move sprite
sprite("Planet Cute:Character Boy",cb.x,cb.y) -- draw sprite
done=true -- tween is done, allow next jump or duck
if t.state==MOVING and done then
if t.deltaY<0 then -- flick down
if t.deltaY>0 then -- flick up
In the end the principle of the code worked really well and I had to create some rules around the specific things in my game. But the code idea was really helpful!