This site requires JavaScript, please enable it in your browser!
Greenfoot back
Minion1
Minion1 wrote ...

2013/1/11

getColorAt() only works on world objects, not actor objects. Can change this?

Minion1 Minion1

2013/1/11

#
After doing more experimenting, I've discovered that the "getColorAt" method only appears to detect colors of images from the World classes (like a background), but not from the Actor classes. Is there a way to make it so that the getColorAt() method will detect a color from an Actor class instead? Or is there a method in the Java API that could do it? I'm looking to detect the color of a single pixel of an actor image.
Minion1 Minion1

2013/1/11

#
Or even better, there seems to be a method in the java API called "getPixelColor(int x, int y)" I think this might be what I'm looking for, but I can't seem to import it. It says it's part of java.awt.Robot but when I import that it still can't find the method. Anyone know how to access getPixelColor??
Minion1 Minion1

2013/1/11

#
Ok, I'm giving up now. Nothing works.
danpost danpost

2013/1/11

#
If you want to get the color of a pixel in the image of an actor, use (from within the class of the actor whose image you want the pixel color of):
Color color = getImage().getColorAt(x, y);
The values of 'x' and 'y' are offsets from the top-left corner of the image itself.
You need to login to post a reply.