Search code examples
androidcameralibgdxviewportfreeze

(LibGdx) Screen viewport issue


This is related to Libgdx. I m developing a game which works logically correct.

Problem: When game runs on PC it looks fine (FPS 61) but when run on android (FPS from 47 to 30 keeps falling) (Note 5) its very slow and freezes and closes after a while (Too much stuff appears on screen)

Issue(Most probably) I didnt use camera or viewport in game first.(This makes game hang after a while on phone but not pc)

later I put camera and viewport in game but then viewport shows too little of game scene on hi res screens (I used 1280x720 for viewport and camera), Now game doesnt hang or freeze but very less of scene is visible

What should be viewport and camera setup for all res devices?(examples welcome)

Thanks in advance for any suggestions


Solution

  • Finally solved. The problem was that i was setting camera and viewport resolutions to Gdx.Graphics.getHeight() and width()... which got device height and width.

    Thus main cause of problem.

    What I needed to do was to set camera and viewport resolutions to virtualResolutions(own desired height x width) like @Abhishek pointed. After fixing this, both PC and android device show same screens BUT

    FPS on android device falls from 45 to 30 and game runs slow.(Although both PC and mobile shows same number of textures) I m using using ExtendViewport

    Any suggestions about that?

    SOLUTION : USE ONLY ONE SpriteBatch NO MATTER WHAT (I used more than one mistakenly thus lag)