Jump height depending on how long you hold button

Simply amazing. Thanks for posting the above code (with additions)! I love the sense of community Corona has. [import]uid: 14218 topic_id: 13365 reply_id: 51662[/import]

Amazing code!, thank to much for sharing.
So, how can I do a sprite to move with the bounce moving.
Into the code below, I it could be inserting the lines “-- A sprite sheet with a white ball” into the “local function MovePlayerUpOrDown()”, but I don’t know how to do that.
Can anyone help me with this?.

Thanks

require “sprite”
display.setStatusBar( display.HiddenStatusBar )

– The background
local sky = display.newImage( “background.jpg” )
local baseline = 280
local physics = require (“physics”)

local PlayerUpDownSpeed = 300
local MovePlayerUp = 0
local MovePlayerDown = 0

– A sprite sheet with a white ball
local sheet2 = sprite.newSpriteSheet( “square.png”, 128, 128 )
local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 15)
sprite.add( spriteSet2, “man”, 1, 15, 200, 0 ) – play 15 frames every 200 ms
local instance2 = sprite.newSprite( spriteSet2 )
instance2.x = 3 * display.contentWidth / 4 + 30
instance2.y = baseline - 55
instance2:prepare(“man”)
instance2:play()
–****************************************+++

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, baseline, 480, 90 )
ground:setFillColor( 0x31, 0x5a, 0x18 )
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 , 5 )

end
–*******************************************************–


local function InitGame()

InitPhysics()
CreateGround()
SpawnPlayer()

end
–*******************************************************–

InitGame()

Runtime:addEventListener( “touch”, Touch )
Runtime:addEventListener( “enterFrame” , EnterFrame ) [import]uid: 54055 topic_id: 13365 reply_id: 51813[/import]

Small Change to not make the Player stop it’s x-Movement when jumping:

i know this thread is allready a bit older. but i assume the code is still uptodate.
at least i just used it and it’s working really nice.

one simple addition, just in case someone is really new to corona and didnt figure it out by himself:

[lua]–if you dont want the jump to cancel your movement in the X-axis just add
– one change to your MovePlayerUpOrDown() function

local function MovePlayerUpOrDown()

if MovePlayerUp == 1 then

–getting the current directional movement
local vx , vy = Player:getLinearVelocity()
–putting in vx instead of 0
Player:setLinearVelocity( vx , - PlayerUpDownSpeed )

else

local vx , vy = Player:getLinearVelocity()

Player:setLinearVelocity( vx , vy )

end

end[/lua]

i hope thats the way you do it,
if it’s not, give me a hint how to do it better.

btw. hooray, first post here! hello everybody :wink:

cheers and many many thanks for the jump code, saved me quite some time,
Michael [import]uid: 11133 topic_id: 13365 reply_id: 129647[/import]

Small Change to not make the Player stop it’s x-Movement when jumping:

i know this thread is allready a bit older. but i assume the code is still uptodate.
at least i just used it and it’s working really nice.

one simple addition, just in case someone is really new to corona and didnt figure it out by himself:

[lua]–if you dont want the jump to cancel your movement in the X-axis just add
– one change to your MovePlayerUpOrDown() function

local function MovePlayerUpOrDown()

if MovePlayerUp == 1 then

–getting the current directional movement
local vx , vy = Player:getLinearVelocity()
–putting in vx instead of 0
Player:setLinearVelocity( vx , - PlayerUpDownSpeed )

else

local vx , vy = Player:getLinearVelocity()

Player:setLinearVelocity( vx , vy )

end

end[/lua]

i hope thats the way you do it,
if it’s not, give me a hint how to do it better.

btw. hooray, first post here! hello everybody :wink:

cheers and many many thanks for the jump code, saved me quite some time,
Michael [import]uid: 11133 topic_id: 13365 reply_id: 129647[/import]