Howdy, Stranger!

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

Help with jumping

edited June 2013 in Questions Posts: 23

I am currently making a sidescroller game where my person needs to be able to jump once every time I tap the screen. I have been thinking and thinking about this but nothing I try works. Could anybody please help me.

Comments

  • edited June 2013 Posts: 372

    If your person is a physics body then just give it a velocity upwards when the screen is touched. else if the sprites position is defined by something like SpriteX and SpriteY then maybe you could increase the SpriteY when the screen is touched.
    Something like this:

    function setup()
        b=physics.body(CIRCLE,20)
        b.gravityScale=1
        b.x=WIDTH/2
        b.y=HEIGHT/2
    end
    
    function draw()
        background(0, 0, 0, 255)
        if b.y<20 then
            b.gravityScale=0
            b.linearVelocity=vec2(0,0)
        else
            b.gravityScale=1
        end
        if touches then
            b.linearVelocity=vec2(0,200)
            touches=false
        end
        fill(255, 255, 255, 255)
        ellipse(b.x,b.y,40)
    end
    
    function touched(touch)
        if touch.state==ENDED then
            touches=true
        end
    end
    
  • Posts: 1,976

    Don't set the linear velocity, then if the player was moving it would stop. Use body:applyForce(vec2)

Sign In or Register to comment.