mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-28 08:30:08 +07:00
Fixed Box2D world generation
Fixed Box2D world generation by subtracting tile offset Added Box2D debug renderer Disabled RenderSystem debug subtile flag
This commit is contained in:
parent
3bd3e5f64e
commit
24b6a9d3ed
@ -22,6 +22,10 @@ public class IsometricCamera extends OrthographicCamera {
|
||||
toWorld(pixOffset.x, pixOffset.y, tileOffset.setZero());
|
||||
}
|
||||
|
||||
public Vector2 getTileOffset(Vector2 dst) {
|
||||
return dst.set(tileOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(Vector2 vec) {
|
||||
translate(vec.x, vec.y);
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.riiablo.engine.system.debug;
|
||||
|
||||
import com.badlogic.ashley.core.Engine;
|
||||
import com.badlogic.ashley.core.EntitySystem;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
|
||||
import com.riiablo.map.Box2DPhysicsSystem;
|
||||
import com.riiablo.map.RenderSystem;
|
||||
|
||||
public class Box2DDebugRenderSystem extends EntitySystem {
|
||||
private static final float BOX2D_ZOOM_FACTOR = 0.04419419f;
|
||||
|
||||
RenderSystem renderSystem;
|
||||
Box2DPhysicsSystem physicsSystem;
|
||||
OrthographicCamera camera;
|
||||
Box2DDebugRenderer renderer;
|
||||
|
||||
public Box2DDebugRenderSystem(RenderSystem renderSystem) {
|
||||
setProcessing(false);
|
||||
this.renderSystem = renderSystem;
|
||||
renderer = new Box2DDebugRenderer();
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(true);
|
||||
camera.near = -1024;
|
||||
camera.far = 1024;
|
||||
camera.rotate(Vector3.X, -60);
|
||||
camera.rotate(Vector3.Z, -45);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addedToEngine(Engine engine) {
|
||||
assert physicsSystem == null;
|
||||
physicsSystem = engine.getSystem(Box2DPhysicsSystem.class);
|
||||
assert physicsSystem != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
camera.position.set(renderSystem.iso().position, 0);
|
||||
camera.zoom = BOX2D_ZOOM_FACTOR * renderSystem.zoom();
|
||||
camera.update();
|
||||
renderer.render(physicsSystem.world, camera.combined);
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.riiablo.camera.IsometricCamera;
|
||||
import com.riiablo.engine.component.Box2DComponent;
|
||||
import com.riiablo.engine.component.PositionComponent;
|
||||
import com.riiablo.engine.component.VelocityComponent;
|
||||
@ -76,15 +77,16 @@ public class Box2DPhysicsSystem extends IntervalIteratingSystem implements Entit
|
||||
world.destroyBody(body);
|
||||
}
|
||||
|
||||
public void setMap(Map map) {
|
||||
public void setMap(Map map, IsometricCamera iso) {
|
||||
if (this.map != map) {
|
||||
this.map = map;
|
||||
createBodies();
|
||||
Vector2 tileOffset = iso.getTileOffset(new Vector2()).scl(-1); // offset inverse of tile offset
|
||||
createBodies(tileOffset);
|
||||
if (DEBUG) Gdx.app.debug(TAG, "bodies=" + world.getBodyCount());
|
||||
}
|
||||
}
|
||||
|
||||
private void createBodies() {
|
||||
private void createBodies(Vector2 offset) {
|
||||
IntMap<Filter> filters = new IntMap<>();
|
||||
|
||||
BodyDef def = new BodyDef();
|
||||
@ -116,7 +118,7 @@ public class Box2DPhysicsSystem extends IntervalIteratingSystem implements Entit
|
||||
}
|
||||
|
||||
int lenY = endY - ty;
|
||||
def.position.set((endX + tx) / 2f, (endY + ty) / 2f);
|
||||
def.position.set((endX + tx) / 2f, (endY + ty) / 2f).add(offset);
|
||||
|
||||
PolygonShape shape = new PolygonShape();
|
||||
shape.setAsBox(lenX / 2f, lenY / 2f);
|
||||
|
@ -50,7 +50,7 @@ public class RenderSystem extends EntitySystem {
|
||||
private static final boolean DEBUG = true;
|
||||
private static final boolean DEBUG_MATH = DEBUG && !true;
|
||||
private static final boolean DEBUG_BUFFER = DEBUG && true;
|
||||
private static final boolean DEBUG_SUBTILE = DEBUG && true;
|
||||
private static final boolean DEBUG_SUBTILE = DEBUG && !true;
|
||||
private static final boolean DEBUG_TILE = DEBUG && !true;
|
||||
private static final boolean DEBUG_CAMERA = DEBUG && true;
|
||||
private static final boolean DEBUG_OVERSCAN = DEBUG && true;
|
||||
|
Loading…
Reference in New Issue
Block a user