简体   繁体   中英

Find edge of OrthographicCamera libgdx

I'm trying to learn libgdx and is making a really simple running game where the player just runs along a platform and jumps over boxes. I have the camera going a constant speed so if the player runs in to a box he/she gets left behind by the camera and that part works just fine. The thing i'm having problem with is checking to see if the player is outside of the camera. Is there any way to find the coordinates for one side of the camera view so I can check if the player is outside it or not?

With a bit of thinking I managed to find the solution to the problem myself with this if statement

if(player.getBody().getPosition().x * PPM < cam.position.x - cam.viewportWidth / 2){}

So for anyone else wondering this is one way to get the left side of the camera, don't know if it's the right way but it works for me.

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