Exactly. For your specific layers that deal with your y ordering you'll have to render line by line to put your player (or other game objects) in between those lines at their proper positions.
I think in my SpiderTrap game I do render the layers line by line in a loop - just in case you'll need some snippet code. Source code on my site (see signature). Should be in class AreaMap if I remember correctly...
...yup, I just checked. It's in class AreaMap which is a subclass of TiledMap.
Here is the relevant snippet:
Code:
public void draw(Graphics g) {
int targetCX = 0;
int targetCY = 0;
if (focusObj != null) {
// set center of areamap to focus obj
targetCX = (int) focusObj.getPosition().x;
targetCY = (int) focusObj.getPosition().y;
} else {
// set center of areamap to start position
targetCX = (int) startPos.x * SpiderTrap.TILESIZE;
targetCY = (int) startPos.y * SpiderTrap.TILESIZE;
}
// now smoothly move camera on realCX, realCY to targetCX, targetCY, using cameraDelta
if (Math.abs(targetCX-realCX) > cameraDelta) {
if (targetCX > realCX)
realCX += cameraDelta;
else
realCX -= cameraDelta;
} else
realCX = targetCX;
if (Math.abs(targetCY-realCY) > cameraDelta) {
if (targetCY > realCY)
realCY += cameraDelta;
else
realCY -= cameraDelta;
} else
realCY = targetCY;
int sx = (realCX - SpiderTrap.WIDTH_HALF) / SpiderTrap.TILESIZE;
int sy = (realCY - SpiderTrap.HEIGHT_HALF) / SpiderTrap.TILESIZE;
int ox = (realCX - SpiderTrap.WIDTH_HALF) % SpiderTrap.TILESIZE;
int oy = (realCY - SpiderTrap.HEIGHT_HALF) % SpiderTrap.TILESIZE;
int x = -ox;
int y = -oy;
int height = SpiderTrap.HEIGHT / SpiderTrap.TILESIZE;
// int width = SpiderTrap.WIDTH / SpiderTrap.TILESIZE;
int width = (SpiderTrap.WIDTH / SpiderTrap.TILESIZE) + 1;
// draw ground layer and entities
drawLayer(GROUNDLAYER, x, y, sx, sy, realCX, realCY, width, g, groundEntities);
// draw splatters below all objects
g.translate(-realCX + SpiderTrap.WIDTH_HALF, -realCY + SpiderTrap.HEIGHT_HALF);
// splatSystem.render();
g.resetTransform();
// draw object layer and entities
drawLayer(OBJECTLAYER, x, y, sx, sy, realCX, realCY, width, g, objectEntities);
g.translate(-realCX + SpiderTrap.WIDTH_HALF, -realCY + SpiderTrap.HEIGHT_HALF);
bulletSystem.render();
explosionSystem.render();
effectSystem.render();
g.resetTransform();
// draw top layer and entities
drawLayer(TOPLAYER, x, y, sx, sy, realCX, realCY, width, g, topEntities);
g.translate(-realCX + SpiderTrap.WIDTH_HALF, -realCY + SpiderTrap.HEIGHT_HALF);
ftbEmitter.renderSystem(g);
g.resetTransform();
}
private void drawLayer(int layerIndex, int x, int y, int sx, int sy, int cx, int cy, int width, Graphics g, ArrayList<Entity> entities) {
// draw the layer
Layer layer = (Layer) layers.get(layerIndex);
for (int ty = 0; ty < height; ty++) {
// layer.render(x, y, sx, sy, width, ty, true, tileWidth, tileHeight);
layer.render(x, y, sx, sy, width, ty, true);
}
// draw the entities on this layer
for (Entity entity : entities) {
float xp = -cx + SpiderTrap.WIDTH_HALF + entity.getX();
float yp = -cy + SpiderTrap.HEIGHT_HALF + entity.getY();
if ((xp > -50) && (yp > -50) && (xp < SpiderTrap.WIDTH + 50) && (yp < SpiderTrap.HEIGHT + 50)) {
g.translate(-cx + SpiderTrap.WIDTH_HALF, -cy + SpiderTrap.HEIGHT_HALF);
entity.draw(g);
g.resetTransform();
}
}
}
Hope that helps,
Tommy