Page 1 of 1
Wrapping mouse cursor?
Posted: Wed Apr 14, 2010 4:12 pm
by replicate
I've searched high and low, and haven't been able to find anything relevant, so here goes: Could anyone tell me a simple way to make the mouse cursor wrap around the screen edges? ie. if you're moving your mouse all the way to the right and hit the screen edge, I want the cursor to jump back to the left side of the screen, and continue moving right until you quit moving in that direction. Vice versa in the other direction. Any help would be greatly appreciated, and thanks in advance.
Re: Wrapping mouse cursor?
Posted: Wed Apr 14, 2010 4:14 pm
by nevon
I suppose you could use love.mouse.setPosition to move it to the opposite side when you reach the edge of the window.
Re: Wrapping mouse cursor?
Posted: Wed Apr 14, 2010 4:22 pm
by kalle2990
This should do that
Code: Select all
function love.load()
w = love.graphics.getWidth()
h = love.graphics.getHeight()
margin = 80 --This is a safe value, if you're running fullscreen, set this to something smaller. Like 5
end
function love.update(dt)
local x, y = love.mouse.getPosition()
local newX, newY = x, y
if x < margin then
newX = w - margin
end
if x > w - margin then
newX = margin
end
if y < margin then
newY = h - margin
end
if y > h - margin then
newY = margin
end
if newX ~= x or newY ~= y then
love.mouse.setGrab(true)
love.mouse.setPosition(newX, newY)
love.mouse.setGrab(false)
end
end
Re: Wrapping mouse cursor?
Posted: Wed Apr 14, 2010 5:28 pm
by replicate
Thank you both kindly! I <3 this community.