java - libgdx - Camera doesnt properly follow player - runs off screen -


I am developing a PBGDX RPG desktop game like Pocaine style (top down scene) in the game I have an orthographic camera To use the player to follow, he is created using Tiles around a Tmx map. The problem I am facing is that when the player continues in the map, the player eventually runs the camera, prevents him from walking on the screen, of which he is centered. I have searched Google and YouTube, which did not find anything that solves the problem.

WorldRenderer.class

  Public class trustworthy {Private TiledMap map; Private orthogonaltilimmander renderer renderer; Public transit camera camera; Private player player; TiledMapTileLayer Layer; Public Worldrender () {map = new TmxMapLoader (). Load ("map / testMap2.tmx"); Renderer = new orthogonaltililmermmarker (map); Player = new player (); Camera = new orthographic camera (); Camera.viewportWidth = Gdx.graphics.getWidth () / 2; Camera.viewportHeight = Gdx.graphics.getHeight () / 2; } Public Zero Render (Float Delta) {camera.position.set (player.getX () + player.getWidth () / 2, player .getY () + player.getHeight () / 2, 0); Camera.update (); Renderer.setView (camera); renderer.render (); Player.render (delta); }}   

Player.class

  public class player {public vector 2 status; Private Float Hill Speed; Private SpratchBatch batch; Animation Public Animation A; Private Texture Tex; Private StructureTreviewFrame; Private Texture Reason [] [] Frame; Private flat frametime; Public player () {condition = new vector 2 (100, 100); Move = 2f; Batch = new spritebatch (); CreatePlayer (); } Public Zero Make Player () {tex = new texture ("Sprites / Image Page"); Frames = Texture Silk Split (Tech, Tech .getWidth) / 3, Tech.GateHight () / 4); A = new animation (0.10f, frame [0]); } Public Zero Render (Float Delta) {handleInput (); Frames + delta; CurrentFrame = an.getKeyFrame (FrameTime, True); Batch.begin (); Batch.rara (currentframe, position.ex, position.i, 50, 50); Batch.end (); } Public Zero Handle Input () (if (Gdx.input.isKeyPressed (Keys.UP)) {a = new animation (0.10f, frame [3]); position.y + = moveSpeed;} if (Gdx.input. isKeyPressed (Keys.DOWN) {A = new animation (0.10f, frame [0]); position.y - = moveSpeed;} if (Gdx.input.isKeyPressed) {a = new animation (0.10 F, frame [1]); position.x - = moveSpeed;} if (Gdx.input.isKeyPressed (Keys.RIGHT)) {a = new animation (0.10f, frame [2]); Position.x + = moveSpeed ;} If (! Gdx.input.isKeyPressed (Keys.ANY_KEY)) {a = new animation (0.10f, frame [0]);}} Public Zero Disposal () {batch.dispose ()}} Public Float getX ) {return position.x;} Public float getY () {return status y}} public int getWidth () {return 32;} public int getHeight () {return 32;}}    

  player.render (delta);   

The < Code> SpriteBeach is built into the player category.
It does not use SpriteBeach camera of matrix and hence it always shows only part of the world, where Player exits screen.
There are now 2 possibilities: Use spritebatch.SetProjectionMatrix (camera.combined) . For this, you need to store the context of the player class inside the camera .
or use a very cleaner solution: Separate the logic and the scene Use a square for drawing maps and player.
Instead of calling WorldRenderer then player.render () you should attract for the player drawing there you have the renderer You can use s SpriteBeach ( renderer.getSpriteBatch () should work). I think this SpriteBeach already uses the camera.combined matrix , so you do not have to worry about it.

Hope this helps.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -