GeeCON Prague 2014*
The moose likes Game Development and the fly likes How do I get the (x, y) coords for A colour? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Game Development
Bookmark "How do I get the (x, y) coords for A colour?" Watch "How do I get the (x, y) coords for A colour?" New topic
Author

How do I get the (x, y) coords for A colour?

August Korvell
Greenhorn

Joined: Oct 05, 2013
Posts: 1
Hello, I am trying to get the coordinates for a specificcolour in a picture.

private void loadLevelFromFile() {
try {
this.image = ImageIO.read(Level.class.getResource(this.imagePath));
this.width = image.getWidth();
this.height = image.getHeight();
tiles = new byte[width * height];
this.loadTiles();

} catch (IOException e) {
e.printStackTrace();
}
}

private void loadTiles() {
int[] tileColours = this.image.getRGB(0, 0, width, height, null, 0,
width);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
tileCheck: for (Tile t : Tile.tiles) {
if(t != null && t.getLevelColour() == tileColours[x+y*width]){
this.tiles[x+y*width] = t.getId();
break tileCheck;
}
}
}
}
}
I have these functions to get it, but I do not know how I can get them in another class.

I need it to spawn a entity on a spcific colour on my level map.

I hope you can help :)
 
GeeCON Prague 2014
 
subject: How do I get the (x, y) coords for A colour?