Page 1 of 1

love.keyboard.isDown() Function

Posted: Thu Jan 03, 2013 8:16 am
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

Re: love.keyboard.isDown() Function

Posted: Thu Jan 03, 2013 9:38 am
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

Re: love.keyboard.isDown() Function

Posted: Thu Jan 03, 2013 9:44 am
by Nah-Trowen
Thanks didn't notice that.

Re: love.keyboard.isDown() Function

Posted: Thu Jan 03, 2013 12:16 pm
by Lafolie
You should be using dt when moving your character around.

Re: love.keyboard.isDown() Function

Posted: Fri Jan 04, 2013 7:08 am
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