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.
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
Don’t set the linear velocity, then if the player was moving it would stop. Use body:applyForce(vec2)