Changed translation amount

Changed translation amount
Added support for toTile50 for position coords because of centering
Display iso position and tile position
Changed access of offset and position
This commit is contained in:
Collin Smith 2019-05-10 00:20:58 -07:00
parent a7682d8743
commit 2ae55d9eb8
2 changed files with 28 additions and 9 deletions

View File

@ -8,8 +8,8 @@ import com.riiablo.util.EngineUtils;
public class IsometricCamera extends OrthographicCamera {
private final Vector2 tmp = new Vector2();
private final Vector2 offset = new Vector2();
private final Vector2 position = new Vector2();
public final Vector2 offset = new Vector2();
public final Vector2 position = new Vector2();
public IsometricCamera() {}
@ -70,4 +70,14 @@ public class IsometricCamera extends OrthographicCamera {
dst.y = y < 0 ? MathUtils.floor(y) : MathUtils.floorPositive(y);
return dst;
}
public Vector2 toTile50(Vector2 worldCoords) {
return toTile50(worldCoords.x, worldCoords.y, worldCoords);
}
public Vector2 toTile50(float x, float y, Vector2 dst) {
dst.x = x < 0 ? MathUtils.round(x) : MathUtils.roundPositive(x);
dst.y = y < 0 ? MathUtils.round(y) : MathUtils.roundPositive(y);
return dst;
}
}

View File

@ -46,6 +46,7 @@ public class CameraTool extends ApplicationAdapter {
font = new BitmapFont();
iso = new IsometricCamera();
shapes = new ShapeRenderer();
shapes.setAutoShapeType(true);
center.set(shapes.getTransformMatrix()).translate(
Gdx.graphics.getWidth() / 2,
Gdx.graphics.getHeight() / 2,
@ -68,25 +69,26 @@ public class CameraTool extends ApplicationAdapter {
@Override
public boolean keyDown(int keycode) {
final float AMOUNT = 0.25f;
switch (keycode) {
case Keys.W:
case Keys.UP:
iso.translate(0, -1);
iso.translate(0, -AMOUNT);
break;
case Keys.S:
case Keys.DOWN:
iso.translate(0, 1);
iso.translate(0, AMOUNT);
break;
case Keys.A:
case Keys.LEFT:
iso.translate(-1, 0);
iso.translate(-AMOUNT, 0);
break;
case Keys.D:
case Keys.RIGHT:
iso.translate( 1, 0);
iso.translate( AMOUNT, 0);
break;
}
return super.keyDown(keycode);
@ -96,6 +98,7 @@ public class CameraTool extends ApplicationAdapter {
final Vector2 vec2 = new Vector2();
final Vector2 loc = new Vector2();
final Vector2 pos = new Vector2();
@Override
public void render() {
@ -157,14 +160,20 @@ public class CameraTool extends ApplicationAdapter {
shapes.setColor(Color.SALMON);
DebugUtils.drawDiamond(shapes, vec2.x, vec2.y - Tile.SUBTILE_HEIGHT50, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);
shapes.set(ShapeRenderer.ShapeType.Filled);
shapes.setColor(Color.GREEN);
shapes.point(vec2.x, vec2.y, 0);
shapes.rect(vec2.x - 0.5f, vec2.y - 0.5f, 1, 1);
} shapes.end();
pos.set(iso.position);
iso.toTile50(pos);
batch.begin();
StringBuilder builder = new StringBuilder()
.append(loc)
.append(vec2);
.append(iso.position).append('\n')
.append(pos).append('\n')
.append(loc).append('\n')
.append(vec2).append('\n');
font.draw(batch, builder.toString(), 0, Gdx.graphics.getHeight());
batch.end();
}