posted 10 years ago
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 :)