Run this plug and play code, it’s not the greatest but it shows you how this might be done;
[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 8 )
local jumpHeight = 100
local floor = display.newRect( 0, 470, 320, 10 )
local player = display.newRect( 140, 400, 40, 40 )
player:setFillColor(200,0,0)
physics.addBody(floor, “static”, {bounce = 0})
physics.addBody(player, “dynamic”, {density = 1.0, friction = 0.3, bounce = 0})
local jumpBtn = display.newCircle( 290, 400, 20 )
local function jump(event)
if event.phase == “began” then
jumpTimer = timer.performWithDelay(10, function() jumpHeight=jumpHeight+5 end, -1)
elseif event.phase == “ended” then
player:setLinearVelocity(0,-jumpHeight)
timer.cancel(jumpTimer)
jumpHeight = 100
end
end
jumpBtn:addEventListener(“touch”, jump)[/lua]
Peach
[import]uid: 52491 topic_id: 20562 reply_id: 80981[/import]