I did not mean to promote my code, over Slick, or saying that mine is better. I have a lot of respect for kevglass’ code. However, I am stating that the only thing changing in MY code, is that one call to g.drawRect, which seems to change a lot. More than just a rect. Now, this seems to me, like something is wrong.
I’m having my drawing logic in the screen, and not in the brick, because my Brick is only a data object. I find it more correct, to have it in screen.
Screen is drawing brick - not brick.
The code I posted is very relevant:
// World-rendering
int startingX = cameraX / 10;
g.setColor(Color.green);
for (int x = startingX; x < 50 + startingX; x++) {
for (int y = 0; y < 20; y++) {
if (level.getBrick(x, y) != null) {
int k = x * 10;
int startDrawX = k - cameraX;
int startDrawY = 200 - ((y + 1) * 10);
g.drawRect(startDrawX, startDrawY, 10, 10);
Brick brick = level.getBrick(x, y);
BRICK_TYPE type = brick.getType();
ResourceManager.TILE image = type.getImage();
g.drawImage(graphics.getSprite(image.getX(), image.getY()), startDrawX, startDrawY);
}
}
}
Applies to the first picture.
// World-rendering
int startingX = cameraX / 10;
g.setColor(Color.green);
for (int x = startingX; x < 50 + startingX; x++) {
for (int y = 0; y < 20; y++) {
if (level.getBrick(x, y) != null) {
int k = x * 10;
int startDrawX = k - cameraX;
int startDrawY = 200 - ((y + 1) * 10);
//g.drawRect(startDrawX, startDrawY, 10, 10);
Brick brick = level.getBrick(x, y);
BRICK_TYPE type = brick.getType();
ResourceManager.TILE image = type.getImage();
g.drawImage(graphics.getSprite(image.getX(), image.getY()), startDrawX, startDrawY);
}
}
}
Applies to the second, and third.
Also, I believe I’ve tried everything with this. I mean; there isn’t much to try. The comment should remove the green rects. Obviously, it’s not doing that.
EDIT: It seems to boil down to, wether I draw the rects first, or the images first. If the rect if not drawn before the images, it f’s up.
Can anyone suggest a better way to debug this? Things I could try?
if (level.getBrick(x, y) != null) {
Brick brick = level.getBrick(x, y);
BRICK_TYPE type = brick.getType();
ResourceManager.TILE image = type.getImage();
int k = x * 10;
int startDrawX = k - cameraX;
int startDrawY = 200 - ((y + 1) * 10);
Image drawImage = graphics.getSprite(image.getX(), image.getY());
g.drawImage(drawImage, startDrawX, startDrawY);
//g.drawRect(startDrawX, startDrawY, 10, 10);
}
Same exact result.