Page 1 of 1
Quad getPixel() or getPixels() not possible ?
Posted: Sun Dec 01, 2024 8:44 am
by gcmartijn
H!,
I have a quad and need the get the pixels or getPixel, but that is not possible ?
https://love2d.org/wiki/Quad
And
https://love2d.org/wiki/love.image.newImageData don't allow a Quad
https://love2d.org/wiki/ImageData
Thanks for the info?
Re: Quad getPixel() or getPixels() not possible ?
Posted: Mon Dec 02, 2024 12:58 pm
by pgimeno
A quad is just a rectangle, so to say; it does not contain the image data itself, and you're right,
ImageData does not support quads. But you can simulate it easily with
Quad:getViewport:
Code: Select all
local function getQuadPixel(imgData, quad, x, y)
local x0, y0 = quad:getViewport()
return imgData:getPixel(x - x0, y - y0)
end
If that function could receive pixels outside the quad extents, and you want to do something about it, you'll have to account for the width and height of the quad as well:
Code: Select all
local function getQuadPixel(imgData, quad, x, y)
local x0, y0, w, h = quad:getViewport()
if x >= x0 and y >= y0 and x < x0 + w and y < y0 + h then
return imgData:getPixel(x - x0, y - y0)
end
-- Do something to deal with coordinates out of the quad.
-- In the example below, it reports an error.
error("Coordinates out of the quad")
end
Re: Quad getPixel() or getPixels() not possible ?
Posted: Mon Dec 02, 2024 4:57 pm
by gcmartijn
Ah din't know about the quad viewport. Thanks!