Page 1 of 1

Screen detection help!

Posted: Sun Dec 22, 2013 6:11 am
by UC101
Hello, I'm new to the Love2d engine and i'm trying to make my object stay inside the window. my script is only acting as if it doesn't detect the bottom edge of the window and the object goes underneath it.. here is my code:

Code: Select all

function map_collisions()
	if player.x < 0 then
		player.x = 0
	end	
	
	if player.y < 0 then
		player.y = 0
	end
		
	if player.y + player.graphic:getHeight() > 700 then
		player.y = 700 - player.graphic:getHeight()
	end
		
	if player.x + player.graphic:getWidth() > 800 then
		player.x = 0 
		
	end
end

Re: Screen detection help!

Posted: Sun Dec 22, 2013 8:24 am
by Roland_Yonaba
As far as I can see, the code seems okay. Can you post a *.love file ?
Thanks.

Re: Screen detection help!

Posted: Sun Dec 22, 2013 8:41 am
by kikito
If you haven't touched the default settings, then the screen height is 600, not 700. You can use [wiki]love.graphics.getWidth[/wiki] and [wiki]love.graphics.getHeight[/wiki] to get the dimensions.