Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hit detection by color

 
Jamie Brandon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is for a simple point and click game. Because of the nature of the game I would prefer to use the swing UI rather than using basic graphics (it would take too long to explain why). At the moment Im using labels with gif icons and transparent backgrounds. Is there any way to find the color displayed at the point where the mouse clicked? I realise that the color model holds data for each pixel but i dont know how the coordinates map to the pixel number and the RGB at each pixel just seems to be counting upwards in any case. Also, Id be grateful if someone could explain how the gif transparancies work and what RGB value is registered for a transparent background.

Thanks, Jamie
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The PixelGrabber api has an example that shows how to access the ColorModel int[].

This example works in older j2se versions. If you are using j2se 1.4+ you can load your image(s) with ImageIO.read which returns a BufferedImage. In the BufferedImage api you can then use the method getRGB to get your color information.

The PixelGrabber uses a default RGB ColorModel (see PixelGrabber constructor detail). More information is available in the DirectColorModel api.
 
Jamie Brandon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

If a bufferd image would be so easy to use, is there any way to access the biffer used in the swing display or would I have to buffer it myself to do it that way?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic