Code: Select all
r, g, b, a = ImageData:getPixel( x, y )
Also, when I used setPixel in the update method, I got a 'attempt to access index 'ImageData'. Can someone tell me what is going wrong here?
Code: Select all
r, g, b, a = ImageData:getPixel( x, y )
Code: Select all
local r, g, b, a = ImageData:getPixel(x, y)
-- compare r, g, b, a
-- OR
local t = {ImageData:getPixel(x, y)} -- d'oh!
-- compare t[1], t[2], t[3], t[4]
Code: Select all
local t = {ImageData:getPixel(x, y)}
Code: Select all
--In load
coverData = love.image.newImageData("overlay.png");
--in Update
if love.mouse.isDown("l") then
local r, g, b, a = coverData:getPixel(love.mouse.getX(), love.mouse.getY());
if (r,g,b,a == 0, 0, 0, 255) then
coverData:setPixel(love.mouse.getX(), love.mouse.getY(), 40, 40, 40, 255);
end
end
This won't work, because t is a different table than {0,0,0,255} even if t = {0,0,0,255}.thelinx wrote:dont look please
Code: Select all
local r, g, b = coverData:getPixel(love.mouse.getX(), love.mouse.getY());
if r + g + b == 0 then
coverData:setPixel(love.mouse.getX(), love.mouse.getY(), 40, 40, 40)
end
Code: Select all
coverData:setPixel(love.mouse.getX(), love.mouse.getY(), 40, 40, 40, 255);
Neat! Thanks, problem solved. The code I used if anyone is interested:thelinx wrote:Convert it into an image, draw that image.
Code: Select all
--This code will reveal what's behind it because of setPixel being set to invisible
function love.update(dt)
if love.mouse.isDown("l") then
local r, g, b = coverData:getPixel(love.mouse.getX(), love.mouse.getY());
if r + g + b == 0 then
coverData:setPixel(love.mouse.getX(), love.mouse.getY(), 0, 0, 0, 0)
end
end
imagesData = love.graphics.newImage(coverData);
end
function love.draw()
love.graphics.draw(imagesData, 0, 0);
end
You can't compare multiple values like that AFAIK. UseMaholain wrote:Code: Select all
if (r,g,b,a == 0, 0, 0, 255) then
Code: Select all
if r == 0 and g == 0 and b == 0 and a == 255 then[/quote]
Summing r, g and b and comparing against zero is more efficient I think, but it only works for black (sum == 0) and white (sum == 765).
Cheers,
Andre
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests