• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic