Improved object order rendering

Made MapRenderer aware of entities and made them render behind walls better
Fixed issue where animations were playing too quickly
This commit is contained in:
Collin Smith 2019-02-15 21:11:59 -08:00
parent 3348098ace
commit 247e62ff2b
2 changed files with 28 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Bits;
import com.badlogic.gdx.utils.IntMap;
import java.util.Arrays;
@ -85,6 +86,8 @@ public class MapRenderer {
// DT1 mainIndexes to not draw
final Bits popped = new Bits();
IntMap<? extends Entity> entities;
public MapRenderer(PaletteIndexedBatch batch, OrthographicCamera camera) {
this.batch = batch;
this.camera = camera;
@ -95,6 +98,10 @@ public class MapRenderer {
camera.update();
}
public void setEntities(IntMap<? extends Entity> entities) {
this.entities = entities;
}
public void setMap(Map map) {
if (this.map != map) {
this.map = map;
@ -250,8 +257,10 @@ public class MapRenderer {
break;
case Map.SHADOW_OFFSET:
break;
case Map.WALL_OFFSET: case Map.WALL_OFFSET + 1: case Map.WALL_OFFSET + 2: case Map.WALL_OFFSET + 3:
case Map.WALL_OFFSET:
drawEntities(batch, stx, sty);
drawObjects(batch, zone, stx, sty);
case Map.WALL_OFFSET + 1: case Map.WALL_OFFSET + 2: case Map.WALL_OFFSET + 3:
drawWall(batch, tile, px, py);
break;
case Map.TAG_OFFSET:
@ -287,6 +296,17 @@ public class MapRenderer {
batch.draw(texture, px, py, texture.getRegionWidth() + 1, texture.getRegionHeight() + 1);
}
void drawEntities(PaletteIndexedBatch batch, int stx, int sty) {
if (entities == null) return;
for (Entity entity : entities.values()) {
Vector3 position = entity.position();
if ((stx <= position.x && position.x < stx + Tile.SUBTILE_SIZE)
&& (sty <= position.y && position.y < sty + Tile.SUBTILE_SIZE)) {
entity.draw(batch);
}
}
}
void drawObjects(PaletteIndexedBatch batch, Map.Zone zone, int stx, int sty) {
for (Entity entity : zone.entities) {
Vector3 position = entity.position();

View File

@ -403,14 +403,14 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
player.drawDebug(Diablo.shapes);
Diablo.shapes.end();
b.setProjectionMatrix(camera.combined);
b.begin();
//b.setProjectionMatrix(camera.combined);
//b.begin();
for (Player p : entities.values()) {
p.draw(b);
}
//for (Player p : entities.values()) {
// p.draw(b);
//}
b.end();
//b.end();
b.setProjectionMatrix(Diablo.viewport.getCamera().combined);
//Diablo.shapes.setAutoShapeType(true);
@ -436,6 +436,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
//camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
mapRenderer = new MapRenderer(Diablo.batch, camera);
mapRenderer.setMap(map);
mapRenderer.setEntities(entities);
mapRenderer.resize();
GridPoint2 origin = map.find(Map.ID.TOWN_ENTRY_1);