Page 1 of 1

Is it possible to adjust the opacity of cursor in Love2D?

Posted: Sun Jan 06, 2019 6:35 pm
by kylarlyrik
So, I am using a custom cursor that I made. I wonder if there is way to lower the opacity of my custom cursor.

Re: Is it possible to adjust the opacity of cursor in Love2D?

Posted: Sun Jan 06, 2019 7:20 pm
by ReFreezed
There's no way to dynamically change the opacity of the cursor. You can load the cursor image as ImageData and then change the alpha value for all pixels. Then you use the ImageData as argument for love.mouse.newCursor().

Re: Is it possible to adjust the opacity of cursor in Love2D?

Posted: Sun Jan 06, 2019 7:45 pm
by zorg
(Expanding the previous idea, you could create multiple imagedata, change the alpha values differently for each, then each frame, set a different cursor image; but it might be very resource intensive (or it might not be, check the wiki for warnings or just test it yourself :3 ))

Re: Is it possible to adjust the opacity of cursor in Love2D?

Posted: Sun Jan 06, 2019 9:14 pm
by pgimeno
(Image):replacePixels might work for updating the image. I haven't tested it, so caveat emptor.

Re: Is it possible to adjust the opacity of cursor in Love2D?

Posted: Mon Jan 07, 2019 12:56 am
by kylarlyrik
Thanks to ReFreezed, zorg, and pgimeno, I found a solution to how I can change my cursor's opacity.
This is to anyone who wants to do the same:

Code: Select all

cursorData = love.image.newImageData("path/to/image")
cursorData:mapPixel(function(x, y, r, g, b, a) return r, g, b, a/2 end)
cursor = love.mouse.newCursor(cursorData, 0, 0)
love.mouse.setCursor(cursor)
The part where I divide "a" by 2 is defining how transparent it is. You can increase the number that is being divided by "a" to make it even more transparent.