This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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 :)
 
Don't get me started about those stupid light bulbs.
 
subject: How do I get the (x, y) coords for A colour?
 
Similar Threads
Two dimensional array problem
static problem.
mandelbrot casse tete
applet problems
How to Tile an Image on a JLabel or a JPanel?