locking the mouse to the screen
Posted: Sun Sep 02, 2012 1:48 am
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,
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!
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