So I've been investigating further, this is a mockup of what ends up happening in my game, if the rectangle were the hex grid of my game:
Code: Select all
local fullscreen = true
function love.load()
love.graphics.setMode(1680, 1050, fullscreen, false, nil)
rectWidth = love.graphics.getWidth() / 2
rectHeight = love.graphics.getHeight() / 2
rectLeft = math.floor(love.graphics.getWidth()/4 + 0.5)
rectTop = math.floor(love.graphics.getHeight()/4 + 0.5)
end
function inRect(x, y)
if x < rectLeft or x > rectLeft + rectWidth or
y < rectTop or y > rectTop + rectHeight
then
return false
else
return true
end
end
local prevX, prevY = love.mouse.getPosition()
function love.update(dt)
local x, y = love.mouse.getPosition()
if inRect(prevX, prevY) and not inRect(x, y) then
love.mouse.setVisible(true)
elseif inRect(x, y) and not inRect(prevX, prevY) then
love.mouse.setVisible(false)
end
prevX, prevY = x, y
end
function love.draw()
love.graphics.setColor(100, 100, 100)
love.graphics.rectangle('fill', rectLeft, rectTop, rectWidth, rectHeight)
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle('fill', love.mouse.getX(), love.mouse.getY(), 10, 10)
end
function love.mousepressed()
love.event.push("q")
end
Try to move the mouse out, the mouseout code detects the pointer should change, that resets the pointer to the center, so you never mouse out.
Searching around for SDL bugs I found this thread:
http://forums.libsdl.org/viewtopic.php? ... dcbdca7601
which recommends using the code
Code: Select all
void MyShowCursor( int show )
{
int x, y;
SDL_GetMouseState( &x, &y );
SDL_ShowCursor( show ? SDL_ENABLE : SDL_DISABLE );
SDL_WarpMouse( x, y );
}
So I made the closest equivalent I could to that in love.
Code: Select all
local fullscreen = true
function love.load()
love.graphics.setMode(1680, 1050, fullscreen, false, nil)
rectWidth = love.graphics.getWidth() / 2
rectHeight = love.graphics.getHeight() / 2
rectLeft = math.floor(love.graphics.getWidth()/4 + 0.5)
rectTop = math.floor(love.graphics.getHeight()/4 + 0.5)
end
function inRect(x, y)
if x < rectLeft or x > rectLeft + rectWidth or
y < rectTop or y > rectTop + rectHeight
then
return false
else
return true
end
end
local prevX, prevY = love.mouse.getPosition()
function love.update(dt)
local x, y = love.mouse.getPosition()
if inRect(prevX, prevY) and not inRect(x, y) then
love.mouse.setVisible(true)
love.mouse.setPosition(x, y)
elseif inRect(x, y) and not inRect(prevX, prevY) then
love.mouse.setVisible(false)
love.mouse.setPosition(x, y)
end
prevX, prevY = x, y
end
function love.draw()
love.graphics.setColor(100, 100, 100)
love.graphics.rectangle('fill', rectLeft, rectTop, rectWidth, rectHeight)
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle('fill', love.mouse.getX(), love.mouse.getY(), 10, 10)
end
function love.mousepressed()
love.event.push("q")
end
And now instead of being unable to get the mouse out of the rectangle, I can no longer get it in.