I guess it is worth pointing out that whenever checking the wiki, heed the warning in a yellow box, if there is one. Because in your code you called love.mouse.newCursor in love.draw, it creates a new cursor object every time love.draw is called, which can cause a fair few issues in terms of memory usage.
As for your original issue, I can't immediately spot what your error might be. However, because you call love.mouse.setVisible, and set the visibility to false, you won't be able to see the new cursor you set. You want your cursor to be visible (true), not invisible (false).
Last edited by MrFariator on Wed Apr 20, 2022 6:12 am, edited 1 time in total.
function love.load()
cursor = love.graphics.newImage("cursor.png")
love.mouse.setVisible(false)
love.mouse.setGrabbed(true)
end
function love.update(dt)
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
end
end
function love.draw()
love.graphics.draw(cursor, love.mouse.getX() - cursor:getWidth() / 2, love.mouse.getY() - cursor:getHeight() / 2)
end
Also, thank you for devoting some time to this.
The quit code is important, because without that, you'd be stuck in that window, unless you know enough to press 'alt + f4'.
There is an issue with that code, however. If you define love.keypressed inside the love.update, the keypressed callback will be defined every update tick, when this would suffice:
MrFariator wrote: ↑Thu Apr 21, 2022 2:13 am
There is an issue with that code, however. If you define love.keypressed inside the love.update, the keypressed callback will be defined every update tick, when this would suffice:
function love.update(dt)
-- update code
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
end
This defines the love.keypressed callback only once, and that's all that's needed in this scenario.
I tried this before, it didn't work, but that might have been a problem with how I wrote it. I'll try it again. Also, could you please help with my actual problem? It's in this forum: viewtopic.php?t=92820
function love.load()
cursorImage = love.graphics.newImage("cursor.png")
cursor = love.mouse.newCursor("cursor.png")
love.mouse.setCursor(cursor)
end
function love.draw()
love.graphics.setColor(1, 0, 1)
love.graphics.draw(cursorImage, love.mouse.getPosition())
end
The software cursor will trail behind the hardware cursor.
function love.load()
cursorImage = love.graphics.newImage("cursor.png")
cursor = love.mouse.newCursor("cursor.png")
love.mouse.setCursor(cursor)
end
function love.draw()
love.graphics.setColor(1, 0, 1)
love.graphics.draw(cursorImage, love.mouse.getPosition())
end
The software cursor will trail behind the hardware cursor.
Thank you for your input. I will take that into consideration.