Libgdx box2d issue with dimensions and camera zooming

前端 未结 2 688
北荒
北荒 2021-01-14 21:56

I\'ve got a problem with Box2D. I\'m making a simple 2D game, with a player shooting to enemies. I read that 1 unity in Box2D is equivalent to 1 meter so i shou

相关标签:
2条回答
  • 2021-01-14 22:01

    you don't have to use the zoom to handle this here what i do and it works very well for me

    camera = new OrthographicCamera(SCREEN_WIDTH/PPM, Config.SCREEN_HEIGHT/PPM);
    
    // fix camera to the center of the screen
    camera.position.set(Config.SCREEN_WIDTH/PPM/2f, Config.SCREEN_HEIGHT/PPM/2f, 0);
    
    camera.update();
    

    i put the conversion unit (PPM) to 100

    hope this was helpful

    Good luck

    0 讨论(0)
  • 2021-01-14 22:25

    Don't use PPM, i know you might have seen a lot of tutorials using PPM but instead use virtual pixels or potato pixel for camera and box2d. Here read this wonderful article and this answer. For example:

    OrthographicCamera camera = new OrthographicCamera(20, 11);
    

    Here 20 is any arbitrary number for WIDTH and HEIGHT should be actually WIDTH*Gdx.graphics.getHeight()/Gdx.graphics.getWidth(). You don't need to set any zoom level, leave it to default.

    0 讨论(0)
提交回复
热议问题