love.keyboard.isDown() Function

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Nah-Trowen
Prole
Posts: 8
Joined: Thu Jan 03, 2013 8:04 am

love.keyboard.isDown() Function

Post by Nah-Trowen »

Why does all the controls work except the "down"? It fezze and skips.

Code: Select all

function love.load()

	char1 = love.graphics.newImage("images/alpha.png")
	char1x = 0
	char1y = 0




end

function love.update()
	if love.keyboard.isDown("right")  then
		char1x = char1x + 1
		
	elseif love.keyboard.isDown("left") then
		char1x = char1x - 1
	
	elseif love.keyboard.isDown("up") then
		char1y = char1y - 1
	
	elseif love.keyboard.isDown("down") then
		char1y = char1x + 1
	end
end

function love.draw()

	love.graphics.draw(char1, char1x, char1y)





end
serge1peshcoff
Prole
Posts: 6
Joined: Mon Sep 03, 2012 12:34 pm

Re: love.keyboard.isDown() Function

Post by serge1peshcoff »

Nah-Trowen wrote:Why does all the controls work except the "down"? It fezze and skips.

Code: Select all

function love.load()

	char1 = love.graphics.newImage("images/alpha.png")
	char1x = 0
	char1y = 0




end

function love.update()
	if love.keyboard.isDown("right")  then
		char1x = char1x + 1
		
	elseif love.keyboard.isDown("left") then
		char1x = char1x - 1
	
	elseif love.keyboard.isDown("up") then
		char1y = char1y - 1
	
	elseif love.keyboard.isDown("down") then
		char1y = char1x + 1
	end
end

function love.draw()

	love.graphics.draw(char1, char1x, char1y)





end
I think because you have char1y on the left side and char1x on the right side.
Try changing to:

Code: Select all

elseif love.keyboard.isDown("down") then
		char1y = char1y + 1
	end
Nah-Trowen
Prole
Posts: 8
Joined: Thu Jan 03, 2013 8:04 am

Re: love.keyboard.isDown() Function

Post by Nah-Trowen »

Thanks didn't notice that.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: love.keyboard.isDown() Function

Post by Lafolie »

You should be using dt when moving your character around.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: love.keyboard.isDown() Function

Post by BlackBulletIV »

Lafolie wrote:You should be using dt when moving your character around.
Indeed. Example:

Code: Select all

char1x = char1x + speed * dt
I'm guessing the framerate of your game has been capped at 60 (thanks to v-sync), so you'll probably want to set speed to 60 to get a similar effect to what you were getting before:

Code: Select all

char1x = char1x + 60 * dt
Post Reply

Who is online

Users browsing this forum: MrFariator and 6 guests