Fixed label world to screen coords

Added MapRenderer.projectScaled which is the same as Camera.project, except uses camera viewport width and height
Labels will now output using screen coordinates and clamp to window bounds
This commit is contained in:
Collin Smith 2019-03-02 03:29:17 -08:00
parent 9102c4ba19
commit 0bba0ccb16
2 changed files with 8 additions and 8 deletions

View File

@ -177,9 +177,9 @@ public class MapRenderer {
}
}
public Vector2 project2(Vector2 dst) {
public Vector2 projectScaled(Vector2 dst) {
tmpVec3.set(dst.x, dst.y, 0);
camera.project(tmpVec3);
camera.project(tmpVec3, 0, 0, camera.viewportWidth, camera.viewportHeight);
return dst.set(tmpVec3.x, tmpVec3.y);
}

View File

@ -13,6 +13,7 @@ import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.net.Socket;
@ -460,8 +461,8 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
}
b.end();*/
//layoutLabels();
mapRenderer.prepare(b);
layoutLabels();
//mapRenderer.prepare(b);
b.begin();
for (Actor label : labels) label.draw(b, 1);
b.end();
@ -582,11 +583,10 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
for (Actor label : labels) {
tmp.x = label.getX();
tmp.y = label.getY();
//mapRenderer.camera.
mapRenderer.project2(tmp);
mapRenderer.projectScaled(tmp);
tmp.x = MathUtils.clamp(tmp.x, 0, Diablo.VIRTUAL_WIDTH - label.getWidth());
tmp.y = MathUtils.clamp(tmp.y, 0, Diablo.VIRTUAL_HEIGHT - label.getHeight());
label.setPosition(tmp.x, tmp.y);
System.out.println(tmp);
//if (label.getX() < 0) label.setX(0);
}
}
}