finding color value of pixel on screen

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
fmra
Prole
Posts: 11
Joined: Fri Nov 29, 2013 9:39 pm

finding color value of pixel on screen

Post by fmra »

Is it possible to check the color values of a pixel at x,y on the screen? I have a table with a list of pixels I'm moving around, but I'd like to be able to check unmapped areas of the screen for pixels without nesting iterators.
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: finding color value of pixel on screen

Post by DaedalusYoung »

You can use love.graphics.newScreenshot to get the screen as ImageData, and then use ImageData:getPixel to find the pixel's colour value.

Note that this will create lag when generating the screenshot though, so it's probably best to find another solution.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: finding color value of pixel on screen

Post by veethree »

Draw the stuff to a canvas, Then you can use canvas:getPixel(x, y)
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: finding color value of pixel on screen

Post by slime »

Both of those options are incredibly slow for real-time use. It's best to think of the color of pixels on your screen (or in Canvases) as inaccessible through CPU-side code except in certain circumstances (occasional screenshots), and plan accordingly.
fmra
Prole
Posts: 11
Joined: Fri Nov 29, 2013 9:39 pm

Re: finding color value of pixel on screen

Post by fmra »

yeah, I think I came up with a work around. I created a new table that tallies the x position for each pixel and alters the equations for pixel movement. Insincere, but visually identical to what I was trying to do. Thank you everyone.
Post Reply

Who is online

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