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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
kylarlyrik
Prole
Posts: 2
Joined: Sun Jan 06, 2019 6:30 pm

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

Post 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.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

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

Post 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().
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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 ))
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

(Image):replacePixels might work for updating the image. I haven't tested it, so caveat emptor.
kylarlyrik
Prole
Posts: 2
Joined: Sun Jan 06, 2019 6:30 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests