Why the hell was (Image):getData removed?

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
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Why the hell was (Image):getData removed?

Post by pauls313 »

I can't understand this, forgive me if i'm a little mad, but why the hell remove this function when it was so useful? The wiki now says
Available since LÖVE 0.9.0 and removed in LÖVE 11.0
Create an ImageData from a file, create the Image from that, and keep a reference to the ImageData, instead of using this function.
WHY? WHY MAKE IT SO MUCH HARDER?

Right now in my game I NEEDED this function. I was using it to retrieve the ImageData and look for specific pixels in an image so I could know if the player clicked on the sprite itself or on a transparent pixel. The code was something like this:

Code: Select all

    r, g, b, a = raw:getPixel(rawx + xx, rawy + yy)
    if a > 10 then
      return true
    else
      return false
    end
And I have literally hundreds of different sprites, am I supposed to rework my whole game now? Is there no other way? I wanted to make use of the new LÖVE 11.0 but I guess I'll have to go back to 10.0 if there's no other option here.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Why the hell was (Image):getData removed?

Post by slime »

You can (and have always been able to) create an image using an imagedata, and just reuse the imagedata as you see fit.

Code: Select all

local imagedata = love.image.newImageData("image.png")
local image = love.graphics.newImage(imagedata)

local r, g, b, a = imagedata:getPixel(x, y)
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Re: Why the hell was (Image):getData removed?

Post by pauls313 »

Yes, that's what the wiki says, but I have a lot of loaded images and even more sprites and everything is scripted to make referencing as dynamic as possible. Is it really neccessary to rework all my code and asset loading just to accomodate to this useless change?

The removed function was very useful and efficient, I see no reason at all to remove it.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Why the hell was (Image):getData removed?

Post by slime »

It was removed because it's incompatible with different types of images, it also allows love to reduce its memory usage in the future with different rendering backends.

A super easy way to access imagedata given an image, with minimal code changes, would be to store the imagedata in a table using the image as a key when the image is created. It should be trivial to put that in a function you can replace newImage with wherever you used to call newImage.
Post Reply

Who is online

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