I have FitViewport
with virtual screen size 1920x1080.
viewport = new FitViewport(AssetLoader.VIRTUAL_WIDTH, AssetLoader.VIRTUAL_HEIGHT);
stage = new Stage(viewport);
Also, there is TimeBar
class extended from Actor
class. TimeBar
listing:
public class TimeBar extends Actor {
private Color color;
private ShapeRenderer renderer;
private float time, current;
public TimeBar() {
color = Color.valueOf(AssetLoader.TIMEBAR_COLOR);
renderer = new ShapeRenderer();
renderer.setColor(color.r, color.g, color.b, color.a);
setBounds(10, 10, 1800, 10); //rectangle is wider than the screen! Why?
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
batch.end();
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.rect(getX(), getY(), getWidth(), getHeight());
renderer.end();
batch.begin();
}
}
I've added some logs to render
method:
Gdx.app.log("GameRenderer", "resizing: " + width + " " + height);
Gdx.app.log("GameRenderer", "world width: " + viewport.getWorldWidth());
Gdx.app.log("GameRenderer", "stage width: " + stage.getWidth());
Gdx.app.log("GameRenderer", "Time bar width: " + timeBar.getWidth());
They said:
GameRenderer: world width: 1920.0
GameRenderer: stage width: 1920.0
GameRenderer: Time bar width: 1800.0
But rectangle is wider then the screen, why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…