I'm trying to create my own jumper type game where the player moves up through an infinite y value. The problem I am having is getting the screen size to match up with the android screen.
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Currently I just want the sprite to be drawn in the center of the screen. I'm not worried about the game world size as it will differ from each device.
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(player.getKeyFrame(animationTime), Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
This draws the player somewhere in the upper right corner of the screen. It's my understanding that Gdx.graphics.getwhatever is used to get the dimensions of whatever your device screen is. So I'm wondering if I'm using the viewport class correctly or not?
No comments:
Post a Comment