Eh, may I ask?
I'm having trouble with the keys. I'm doing a ball, make it bounce up. Pressing Up "ONCE" makes it go up.
Code: Select all
if love.keyboard.isDown("up") then
objects.ball.body:applyForce(0, -10)
But When I press UP again (While in Mid-air), it goes up more. How can I fix this?
Because I can spam the Up Arrow Key and make it float all the way and not hitting the ground.
Hope that someone can help. Thanks in Advance. I'm still a new to Love2D.
Thanks!
BTW here's my code:
Code: Select all
function love.load()
world = love.physics.newWorld(0, 0, 800, 800)
world:setGravity(0, 200)
world:setMeter(64)
objects = {}
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 100, 50, 15, 0)
objects.ball.shape = love.physics.newCircleShape(objects.ball.body, 0, 0, 20)
objects.pform1 = {}
objects.pform1.body = love.physics.newBody(world, 0, 0, 0, 0)
objects.pform1.shape = love.physics.newRectangleShape(objects.pform1.body, 100, 100, 100, 10, 0)
objects.pform2 = {}
objects.pform2.body = love.physics.newBody(world, 0, 0, 0, 0)
objects.pform2.shape = love.physics.newRectangleShape(objects.pform2.body, 200, 200, 100, 10, 0)
objects.wall1 = {}
objects.wall1.body = love.physics.newBody(world, 0, 0, 0, 0)
objects.wall1.shape = love.physics.newRectangleShape(objects.wall1.body, 150, 150, 10, 100, 0)
objects.box = {}
objects.box.body = love.physics.newBody(world, 0, 0, 15, 0)
objects.box.shape = love.physics.newRectangleShape(objects.box.body, 150, 50, 25, 25, 0)
love.graphics.setBackgroundColor(255, 0, 255)
love.graphics.setMode(900, 900, false, true, 0)
end
function love.update(dt)
world:update(dt)
if love.keyboard.isDown("right") then
objects.ball.body:applyForce(200, 0)
else
if love.keyboard.isDown("left") then
objects.ball.body:applyForce(-200, 0)
else
if love.keyboard.isDown("up") then
objects.ball.body:applyForce(0, -10)
end
end
end
end
function love.draw()
love.graphics.setColor(0, 255, 0)
love.graphics.polygon("fill", objects.pform1.shape:getPoints())
love.graphics.polygon("fill", objects.pform2.shape:getPoints())
love.graphics.setColor(255, 0, 0)
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius(), 20)
love.graphics.setColor(255, 255, 0)
love.graphics.polygon("fill", objects.box.shape:getPoints())
love.graphics.setColor(0, 0, 255)
love.graphics.polygon("fill", objects.wall1.shape:getPoints())
end
Sorry for the bad COLORS. I SUCK AT COLORS ~ ~