Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Double Jump
Started by Cayendo Apr 05 2019 10:04 AM

1 reply to this topic
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 6 posts
  • Corona SDK

Hi, I am a new at this so I've been following a tutorial that teaches you how to create an endless rounner game. 

function touched( event )
 if hero.isAlive then
  if(event.phase == "began") then
   if(onGround) then
    hero.accel = hero.accel + 25
  if(event.x < gameOver.x + 150 and event.x > gameOver.x - 150 and event.y < gameOver.y + 95 and event.y > gameOver.y - 95) then


From what I found out, this is the function that allows you to jump, however I would like to make it so it double jumps, which is not explained in the tutorial. 


Could someone help me out?

Thanks in advance. 

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 987 posts
  • Corona SDK

You're proving little code so it's hard to tell for sure, but it looks like you code says something like


"if the hero is standing on ground then add 25 to his acceleration".


Presumably when the hero lands "onGround" is set to false or nil.


What you could is create a variable called jumpCounter (with default value zero) and use that instead of the "onGround" variable.


In the "touched" function you could then say something like:


" If jumpCounter is smaller then 2 then: add 1 to the jumpCounter and set hero.accel to hero.accel + 25".


And when then hero lands, you can set the jumpCounter to zero again.


p.s. In code that would read something like this:


if jumpCounter < 2 then

    jumpCounter = jumpCounter + 1

    hero.accel = hero.accel + 25