Lol Howdy,
So, I’ve just developed a level loading system for this project I’m working on. I basically created this method:
private void loadLevel(BufferedImage image){
int w = image.getWidth();
int h = image.getHeight();
for(int xx = 0; xx < h; xx++){
for(int yy = 0; yy < w; yy++){
int pixel = image.getRGB(xx, yy);
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
//Blocks
if(red == 255 && green == 0 && blue == 255) handler.addObject(new Block(xx*64, yy*64, 0, ObjectId.Block));
if(red == 255 && green == 255 && blue == 255) handler.addObject(new Block(xx*64, yy*64, 1, ObjectId.Block));
if(red == 0 && green == 0 && blue == 255) handler.addObject(new Block(xx*64, yy*64, 2, ObjectId.Block));
if(red == 0 && green == 255 && blue == 0) handler.addObject(new Block(xx*64, yy*64, 0, ObjectId.Block));
//Player
if(red == 0 && green == 255 && blue == 0) handler.addObject(new Player(xx*64, yy*64, ObjectId.Player));
}
}
}
& I also made a BufferedImage array as so:
The problem… is that the player loads above some blocks… yet behind others.
I have 3 types of blocks at the moment (0, 1, & 2). So you’re thinking, okay it loads above some types but not othe- WRONG! No, for example… it loads above 0 on some but below on others.
HELP!
Thanks!
-A