Java LibGDX:Tiledmap不在顶部和右侧呈现

时间:2018-12-20 16:34:40

标签: java libgdx viewport

我正在尝试获取一个tiledmap以在整个屏幕上呈现。问题是顶部或右侧的100px,那里的所有内容都是黑色的。我的tiledmap大约有100个tile,因此它应该能够渲染比渲染的更多的东西。

这是现在的样子: my game right now

1:此栏与我预期的一样,目前没有任何可渲染的地方。

2&3:这些条是意外的,因为我的tiledmap中有更多部分要渲染。

我已经尝试将Viewport从StretchViewport更改为FitViewport以及FillViewport,但这并没有任何改变。

这是我在PlayScreen类中的构造函数:

    public Play(GameStateManager gsm) {
       super(gsm);

       //set up box2d
       world = new World(new Vector2(0, -20.81f), true);
       cl = new MyContactListener();
       world.setContactListener(cl);
       b2dr = new Box2DDebugRenderer();

       //set up viewport
       vw = new StretchViewport(1280, 720, cam);
       cam.update();

       //create player
       createPlayer();

       //create tiles
       createTiles();

       //setup box2D cam
       b2dCam = new OrthographicCamera();
       b2dCam.setToOrtho(false, Game.V_WIDTH / PPM, Game.V_HEIGHT / PPM);
    }

这是我的createTiles()方法:

    private void createTiles(){
        loader = new TmxMapLoader();

        tileMap = loader.load("data/lvl1.tmx");
        tmr = new OrthogonalTiledMapRenderer(tileMap);
        cam.update();

        //get the size of the tiles
        tileSize = tileMap.getProperties().get("tilewidth", Integer.class);

        //create box2d bodies for all tiledmap layers
        TiledMapTileLayer layer;

        layer = (TiledMapTileLayer) tileMap.getLayers().get("red");
        createLayer(layer, B2DVars.BIT_RED);

        layer = (TiledMapTileLayer) tileMap.getLayers().get("orange");
        createLayer(layer, B2DVars.BIT_ORANGE);

        layer = (TiledMapTileLayer) tileMap.getLayers().get("yellow");
        createLayer(layer, B2DVars.BIT_YELLOW);

        layer = (TiledMapTileLayer) tileMap.getLayers().get("green");
        createLayer(layer, B2DVars.BIT_GREEN);

        layer = (TiledMapTileLayer) tileMap.getLayers().get("blue");
        createLayer(layer, B2DVars.BIT_BLUE);

        layer = (TiledMapTileLayer) tileMap.getLayers().get("pink");
        createLayer(layer, B2DVars.BIT_PINK);
    }

render()方法:

    public void render(float delta) {
     //clear screen
     Gdx.gl.glClearColor(0.619607843f, 0.79607843137f, 1, 1);
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

     //set cam to follow player
     cam.position.set(
          player.getPosition().x * PPM + Game.V_WIDTH / 4,
          Game.V_HEIGHT / 2, 
          0
     );

     //draw tile map
     tmr.setView(cam);
     tmr.render();

     //draw player
     sb.setProjectionMatrix(cam.combined);
     player.render(sb);

     //draw box2d world
     b2dr.render(world, b2dCam.combined);

     //responsive resizing
     resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}

这是我的主游戏类中的create()方法:

    public void create () {
    Gdx.input.setInputProcessor(new MyInputProcessor());

    //asset managing
    res = new Content();
    res.loadTexture("data/player/player.png", "player");

    sb = new SpriteBatch();
    cam = new OrthographicCamera();
    cam.setToOrtho(false, V_WIDTH, V_HEIGHT);
    hudCam = new OrthographicCamera();
    hudCam.setToOrtho(false, V_WIDTH, V_HEIGHT);
    gsm = new GameStateManager(this);
}

我没想到这款游戏会获得那些黑条,我之前也创造了其他游戏,但他们从未获得过这些黑条。如何删除它们(图像上的2和3)?

0 个答案:

没有答案