How to make character jump farther if screen is touched longer?

Hey,

I wanted to find out if anyone could help me, or give me some sample code on how to make it such that when a person touches the screen longer, my character will jump farther. Thanks! [import]uid: 175550 topic_id: 30906 reply_id: 330906[/import]

Do you already have a regular jump in place? If so, knowing how you currently do that would impact someone giving you a relevant answer. [import]uid: 147305 topic_id: 30906 reply_id: 123606[/import]

Yes i already have a regular jump in place [import]uid: 175550 topic_id: 30906 reply_id: 123609[/import]

Well, hopefully someone with more patience comes along and asks you how you are doing your regular jumping and can assist you. I, however, don’t feel like pulling teeth to help someone so good luck =p [import]uid: 147305 topic_id: 30906 reply_id: 123611[/import]

Super simple example, though as budershank suggested you are much more likely to get help if you provide more information.

[lua]-- Set up physics
require ( “physics” )
physics.start()
physics.setGravity( 0, 9.5 )

–Jump poewr variable
local jumpPower = 0

–Create static ground
local ground = display.newRect( 0, 460, 320, 80 )
physics.addBody(ground, “static”)

–Create dynamic player
local player = display.newRect( 140, 420, 40, 40 )
physics.addBody(player, “dynamic”)
player.isFixedRotation = true

–Jump button
local jumpBtn = display.newCircle(280, 40, 20)

–Jump function
local function jump(event)
if event.phase == “began” then
jumpTimer = timer.performWithDelay(100, function()
jumpPower = jumpPower + 1
end, 0)
elseif event.phase == “ended” then
timer.cancel(jumpTimer)
print (jumpPower)
player:applyForce(0,-jumpPower)
jumpPower = 0
end
end
jumpBtn:addEventListener(“touch”, jump)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 30906 reply_id: 123637[/import]

Do you already have a regular jump in place? If so, knowing how you currently do that would impact someone giving you a relevant answer. [import]uid: 147305 topic_id: 30906 reply_id: 123606[/import]

Yes i already have a regular jump in place [import]uid: 175550 topic_id: 30906 reply_id: 123609[/import]

Well, hopefully someone with more patience comes along and asks you how you are doing your regular jumping and can assist you. I, however, don’t feel like pulling teeth to help someone so good luck =p [import]uid: 147305 topic_id: 30906 reply_id: 123611[/import]

Super simple example, though as budershank suggested you are much more likely to get help if you provide more information.

[lua]-- Set up physics
require ( “physics” )
physics.start()
physics.setGravity( 0, 9.5 )

–Jump poewr variable
local jumpPower = 0

–Create static ground
local ground = display.newRect( 0, 460, 320, 80 )
physics.addBody(ground, “static”)

–Create dynamic player
local player = display.newRect( 140, 420, 40, 40 )
physics.addBody(player, “dynamic”)
player.isFixedRotation = true

–Jump button
local jumpBtn = display.newCircle(280, 40, 20)

–Jump function
local function jump(event)
if event.phase == “began” then
jumpTimer = timer.performWithDelay(100, function()
jumpPower = jumpPower + 1
end, 0)
elseif event.phase == “ended” then
timer.cancel(jumpTimer)
print (jumpPower)
player:applyForce(0,-jumpPower)
jumpPower = 0
end
end
jumpBtn:addEventListener(“touch”, jump)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 30906 reply_id: 123637[/import]