The game has a function to change the cursor when it is over a clickable area and this worked as expected.
However, when I actually clicked the mouse (Actually, I’m using a laptop with touchpad.), it seemed to be using the UNSCALED dimensions for the clicking.
I made a much simpler “game” to test this to see if the problem is something in the complexity of my game, but the results are the same. This simpler game is just a box with text inside to say how many times the box has been clicked. It scales fine, The cusor changes when it is in the box. But the clicking seems to occur based on the original dimensions.
A couple of notes:
The background is black, so in tlfres.lua I change the definition of black to {1,1,0} so the letterboxing is yellow to contrast with the black background.
I used global variables defined in conf.lua for the screen width and height and these variables are used instead of 800, 600, although I did try it with the numbers, not the variables and got the same result.
Any suggestions on what I’m doing wrong? I’ve uploaded the zip file so you can look at the code and the *.love file so you can run it.
Code: Select all
local TLfres = require "tlfres"
local numClicks = 0
boxXleft = 100
boxYtop = 100
boxWidth = 300
boxHeight = 200
boxXright = boxXleft + boxWidth
boxYbottom = boxYtop + boxHeight
function love.load()
stdCursor = love.mouse.newCursor( "bandeira-usa-e.png", 15, 8 )
clickCursor = love.mouse.newCursor( "bandeira-brasil.png", 15, 8 )
love.mouse.setCursor( stdCursor )
end
function love.update(dt)
alterarCursor()
love.mousereleased = function(x, y, button)
if inBox( x, y ) then
numClicks = numClicks + 1
return
end
end
end
function love.draw()love.graphics.setColor(1,1,1)
TLfres.beginRendering( SCREEN_WIDTH, SCREEN_HEIGHT )
love.graphics.rectangle( "fill", boxXleft, boxYtop, boxWidth, boxHeight )
love.graphics.setColor(1,0,0)
love.graphics.print( "This box has been clicked " .. numClicks .. " times", boxXleft + 25, boxYtop + 100 )
TLfres.endRendering()
end
function inBox( x, y )
return (x > boxXleft and x < boxXright) and (y > boxYtop and y < boxYbottom)
end
function alterarCursor()
local x, y = TLfres.getMousePosition( SCREEN_WIDTH, SCREEN_HEIGHT )
if inBox( x, y ) then
love.mouse.setCursor( clickCursor )
else
love.mouse.setCursor( stdCursor )
end
return
end