Page 1 of 1

love.keyboard.setKeyRepeat for only one key(s)?

Posted: Thu Aug 04, 2011 2:57 am
by philipdnichols
Is there any way to use love.keyboard.setKeyRepeat(...) where it will only apply on one or more keys? I'd like to have my character moving using the key repeat, but all the other keys get it applied as well.

Re: love.keyboard.setKeyRepeat for only one key(s)?

Posted: Thu Aug 04, 2011 4:29 am
by Robin
You could use love.keyboard.isDown in love.update, and implement your own keyrepeat mini-system.

Re: love.keyboard.setKeyRepeat for only one key(s)?

Posted: Thu Aug 04, 2011 4:34 am
by philipdnichols
Yeah, I had a feeling I would have to do that...

I was just wondering if maybe there was a shortcut anyone knew about :nyu:

Same Problem.

Posted: Thu Aug 04, 2011 12:52 pm
by Solemnly07
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. :D
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 ~ ~

Re: love.keyboard.setKeyRepeat for only one key(s)?

Posted: Thu Aug 04, 2011 2:18 pm
by Robin
I'd say this is a different issue. You can stop this from happening by only allowing jumping when the player is touching something. I could spell it out for you, but I'd rather you'd think about it for a while first, because you'll learn more that way. If you can't find a solution even then, then we'll help you further.

Re: love.keyboard.setKeyRepeat for only one key(s)?

Posted: Thu Aug 04, 2011 3:58 pm
by Solemnly07
Aha!
That's the best thing to say! :D
Let the beginners get things around. Sure, no problem. I'm still looking for away to solve this.
I'll be back when I'm seriously getting beat up.

Thanks.