I need to make a game in Java for a project.
What I'm trying to do is a game where you have to go through a maze without touching the walls.
Is there a way to get the color of the pixel the mouse is over?
I need to make a game in Java for a project.
What I'm trying to do is a game where you have to go through a maze without touching the walls.
Is there a way to get the color of the pixel the mouse is over?
You want to implement the MouseMotionListener interface and do what Artelius mentioned, namely, get the coordinates of the mouse position and calculate the color of the pixel.
This post answers your question precisely including a complete working code example. Basically, you can create an image from canvas on which you draw and call getRGB() on a pixel on the image.
You probably want java.awt.Robot.getPixelColor(x, y). It'll be faster than grabbing an image.