Here is a quick example on how to accomplish that
it looks very long since i took it from one of my projects
can be shorter but longer is more understandable
you can change the speed of the jump from the first variable
local PlayerUpDownSpeed = 300
i put a touch listener for the whole screen
but you can make it for a jump button only
[lua]display.setStatusBar( display.HiddenStatusBar )
local physics = require (“physics”)
local PlayerUpDownSpeed = 300
local MovePlayerUp = 0
local MovePlayerDown = 0
–*******************************************************–
local function SpawnPlayer()
Player = display.newCircle( 100 , 100 , 16 )
physics.addBody( Player , “daynamic” ,{ bounce = 0 , friction = 0 , density = 1 , radius = 16 } )
Player.isFixedRotation = true
end
–*******************************************************–
–*******************************************************–
local function CreateGround()
local ground = display.newRect( 0 , 300 , 480 , 2 )
physics.addBody( ground , “static” ,{ bounce = 0 , friction = 0 , density = 1 } )
end
–*******************************************************–
–*******************************************************–
local function MovePlayerUpOrDown()
if MovePlayerUp == 1 then
Player:setLinearVelocity( 0 , - PlayerUpDownSpeed )
else
vx , vy = Player:getLinearVelocity()
Player:setLinearVelocity( vx , vy )
end
end
–*******************************************************–
–*******************************************************–
local function Touch(event)
if event.phase == “began” then
MovePlayerUp = 1
elseif ( event.phase == “ended” or event.phase == “canceled” ) then
MovePlayerUp = 0
end
end
–*******************************************************–
–*******************************************************–
local function EnterFrame(event)
MovePlayerUpOrDown()
end
–*******************************************************–
–*******************************************************–
local function InitPhysics()
physics.start( true )
physics.setScale( 100 )
physics.setDrawMode( “normal” )
physics.setGravity( 0 , 9.8 )
end
–*******************************************************–
–*******************************************************–
local function InitGame()
InitPhysics()
CreateGround()
SpawnPlayer()
end
–*******************************************************–
InitGame()
Runtime:addEventListener( “touch”, Touch )
Runtime:addEventListener( “enterFrame” , EnterFrame )[/lua] [import]uid: 46546 topic_id: 13365 reply_id: 50590[/import]