简体   繁体   中英

LibGDX reset or remove Orthographic camera

I'm quite new to LibGDX but not a beginner in java programming. I was making a Flappy bird like game. I used Orthographic camera in my play state so it would follow the bird, but now i want to make a game over screen. I created a class with all the code i need but when i try it still uses the Orthographic camera at the birds position before it died, so the textures on that game over screen are heavily out of place, although isTouched() method is at the right position, so if i press that region i set earlier it restarts the game as it should. The only problem are the textures. Could someone help me solve the problem as i can't figure it out.

I think you want something similar to HUD, which is always displayed on the screen, right?

If so, you can use another orthographic camera, name it hudCam or something you remember. Not sure if necessary but I changed Y-down of the camera to false like this:

hudCamera.setToOrtho(false, WIDTH / 2, HEIGHT / 2); // width and height being the screen size

Then you can just switch between the cameras when drawing.

batch.setProjectionMatrix(camera.combined);
draw...
batch.setProjectionMatrix(hudCamera.combined);
draw HUD stuff...

To get the correct mouse coordinates, just do like you did with the other camera, unproject it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM