Question

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?

Was it helpful?

Solution

You probably want java.awt.Robot.getPixelColor(x, y). It'll be faster than grabbing an image.

OTHER TIPS

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 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top