Wrapping mouse cursor?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Wrapping mouse cursor?
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.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Wrapping mouse cursor?
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?
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?
Thank you both kindly! I <3 this community.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests