views:

278

answers:

3

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?

A: 

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.

Amir Afghani
+1  A: 

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.

Vincent Ramdhanie
+3  A: 

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

Seth
Yes! Thank you, this is exactly what I needed.Thanks a lot everyone!
Alan