Reputation: 13
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?
Upvotes: 1
Views: 1845
Reputation: 5740
You probably want java.awt.Robot.getPixelColor(x, y). It'll be faster than grabbing an image.
Upvotes: 5
Reputation: 103135
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.
Upvotes: 1
Reputation: 38531
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.
Upvotes: 0