Reputation: 992
I have a sprite that the OrthographicCamera
follows. I have a border, that comes into the screens view when the sprite comes close to it, obviously using the OrthographicCamera
.
My code for this is:
float minCameraX = camera.zoom * (camera.viewportWidth / 2)-55;
float maxCameraX = stageWidthHeight.x - minCameraX-80;
float minCameraY = camera.zoom * (camera.viewportHeight / 2)-200;
float maxCameraY = stageWidthHeight.y - minCameraY-250;
// set the camera to either the player or the min/max of the camera based on player position
camera.position.set(
Math.min(maxCameraX, Math.max(playerSprite.getX(), minCameraX)),
Math.min(maxCameraY, Math.max(playerSprite.getY(), minCameraY)),
0);
spriteBatch.setProjectionMatrix(camera.combined);
camera.update();
I also have another texture/sprite (scoreboard) that I want to always have at the bottom of the user's view, and on top of everything.
How would I go about doing this?
Here are some images for what I want to achieve.
Upvotes: 0
Views: 210
Reputation: 992
I found out the solution xD
I just rendered my "scoreboard" in a different SpriteBatch
The suggestions on the right gave me an idea of what to search for.
I LOVE YOU STACKOVERFLOW!!
Sorry, I should have searched more.
Upvotes: 1
Reputation: 2560
I would suggest you should use libgdx's Stage classes and scene2D.
Basically, you can easily create different instances of the Stage
class and add objects to the different stages.
For games I have written, I usually use a "scene" Stage, a "hud" Stage as well as Stage for Dialogs, PauseDialog etc... Each of the Stages can have a different coordinate system and viewport and you will never have to worry about losing something from the screen.
Hope this helps... :)
Upvotes: 1