Page 1 of 1

locking the mouse to the screen

Posted: Sun Sep 02, 2012 1:48 am
by SquareMan
Hello, I've been working on a Terraria Clone In LOVE 2D. Now I've Made a lot of progress such as a simple way to add blocks, random generation, tile-based screen drawing, and until I get a character with tools, an editable random world with the mouse. Now I was wondering if there is a way to lock the mouse to the screen in LOVE 2D. I've tried,

Code: Select all

if love.mouse.getX() < 0 then
	love.mouse.setPosition(0,love.mouse.getY())
end
if love.mouse.getX() > love.graphics.getWidth() then
	love.mouse.setPosition(love.graphics.getWidth(),love.mouse.getY())
end
if love.mouse.getY() < 0 then
	love.mouse.setPosition(love.mouse.getX(),0)
end
if love.mouse.getY() > love.graphics.getHeight() then
	love.mouse.setPosition(love.mouse.getX(),love.graphics.getHeight())
end
but i can still move the mouse off the screen, this is important for windowed mode because if you move the mouse to fast while clicking, it tries to place a block outside of the worlds index. Any help would be appreciated!

Re: locking the mouse to the screen

Posted: Sun Sep 02, 2012 3:22 am
by Santos
Check out love.mouse.setGrab! ^^