Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Hold screen and tap screen

edited June 2014 in General Posts: 316

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?

Thanks

Tagged:

Comments

  • Jmv38Jmv38 Mod
    Posts: 3,295

    yes.
    measure the time t of hold, and if t > t_hold, then duck and do not jump.

  • Posts: 316

    Awesome thank you @Jmv38 !

  • Posts: 316

    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...

  • dave1707dave1707 Mod
    Posts: 7,880

    @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.


    displayMode(FULLSCREEN) function setup() dy=HEIGHT/2 tmr=-1 delay=.2 end function draw() background(40,40,50) fill(255) 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 end if jump then -- perform jump code dy=dy+1 end if duck then -- perform duck code dy=dy-1 end end function touched(t) if t.state==BEGAN then tmr=0 -- reset timer end if t.state==ENDED then duck=false -- reset variables jump=false if tmr>delay then -- timer greater than delay count duck=true -- set duck else jump=true -- set jump end tmr=-1 end end
  • dave1707dave1707 Mod
    Posts: 7,880

    @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.


    supportedOrientations(LANDSCAPE_ANY) displayMode(FULLSCREEN) function setup() done=true cb={x=60,y=300} val=2 end function jumpTween() t1=tween(.5,cb,{y=400},tween.easing.cubicOut) t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone) tween.sequence(t1,t2) end function duckTween() t1=tween(.5,cb,{y=200},tween.easing.cubicOut) t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone) tween.sequence(t1,t2) end function draw() background(40, 40, 50) fill(255) text("flick up to jump, down to duck",WIDTH/2,HEIGHT-100) rect(WIDTH/2,260,20,50) if cb.x<50 or cb.x>WIDTH-50 then -- keep sprite on the screen val=-val end cb.x=cb.x+val -- move sprite sprite("Planet Cute:Character Boy",cb.x,cb.y) -- draw sprite end function tweenDone() done=true -- tween is done, allow next jump or duck end function touched(t) if t.state==MOVING and done then done=false if t.deltaY<0 then -- flick down duckTween() end if t.deltaY>0 then -- flick up jumpTween() end end end
  • Posts: 316

    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!

  • The user and all related content has been deleted.
  • Posts: 316

    Cool!

    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!

Sign In or Register to comment.