hi. I have an applet on to which I have tiled on a background.(background made up of tiles.ie top view of a racing track). now I want to put this background in to the pixelgrabber to identify the colours(and thus do some collision detection). So all I did was import the back buffer image to the pixelgrabber. I get a run time error. Note that the backbuffer is actually an image
can anyone help me.
This is not the way to do good collision detection.
There is a good article on pixel level detection at Java Game Engineering http://www.javage.net/
You only need to use PixelGrabber with Image, with a BufferedImage you can use getData().getPixel(x,y,pixel).
PixelGrabbers work with any kind of image with something like:
int width = = img.getWidth(null);
int height = = img.getHeight(null);
int[] imageData = new int[width * height];
PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, imageData, 0, width);
try
{
pg.grabPixels();
} catch (InterruptedException e)
{
System.err.println("interrupted waiting for pixels!");
}
for(int i=0; i<width; i++)
{
for(int j=0; j<height; j++)
{
int pixel = imageData[i + (j * width)];
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
}
}