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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
philipdnichols
Prole
Posts: 4
Joined: Wed Aug 03, 2011 4:48 am
Location: Boston, MA

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

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

You could use love.keyboard.isDown in love.update, and implement your own keyrepeat mini-system.
Help us help you: attach a .love.
philipdnichols
Prole
Posts: 4
Joined: Wed Aug 03, 2011 4:48 am
Location: Boston, MA

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

Post 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:
User avatar
Solemnly07
Prole
Posts: 4
Joined: Thu Aug 04, 2011 12:22 pm

Same Problem.

Post 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 ~ ~
"I need not to be Right, I just don't have to be Wrong"
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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.
Help us help you: attach a .love.
User avatar
Solemnly07
Prole
Posts: 4
Joined: Thu Aug 04, 2011 12:22 pm

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

Post 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.
"I need not to be Right, I just don't have to be Wrong"
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests