How to check pixel color with Pyglet?
Solution 1:
Maybe you can take a look at this: Setting individual pixels in Pyglet
But in general, img.get_image_data() always returns all the pixels. Here's the documentation to this: https://pyglet.readthedocs.io/en/latest/modules/image/#pyglet.image.AbstractImage.get_image_data
With the ImageData object you can then use 'set_data' or 'get_data' to retrieve or set pixels.
Solution 2:
I've tried the solution proposed by Hyalunar just adding the following method to class Background
, which is called in every mouse motion event:
def check_position(self, x, y):
img_data = road_img.get_region(x, y, 1, 1).get_image_data()
width = img_data.width
data = img_data.get_data('RGB', 3 * width)
print(data[0] + ', ' + data[1] + ', ' + data[2])
And that solution works perfect!