简体   繁体   English

libgdx spritebatch不渲染纹理

[英]libgdx spritebatch not rendering textures

I'm working on a top down RPG game using LibGDX, and am creating an Ortho.. camera for my game. 我正在使用LibGDX制作自上而下的RPG游戏,并正在为我的游戏创建一个Ortho ..相机。 However in doing so, only my tile textures render now. 但是,这样做时,现在仅渲染我的瓷砖纹理。 This is how the render code looks: 这是呈现代码的外观:

Camera initialized as new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 相机初始化为new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

(note that the camera. calls are actually in the world.update method, I just figured I would minimize the amount of code needed on here) (请注意, camera.调用实际上是在world.update方法中,我只是想将这里所需的代码量减至最少)

Updating/Rendering: 更新/渲染:

camera.position.set(getPlayer().getPosition().x, getPlayer().getPosition().y, 0);
camera.update();
batch.setProjectionMatrix(world.getCamera().combined);
batch.begin();
world.render(batch);
batch.end();

the world's render method ends up calling this: 世界上的render方法最终会调用以下代码:

public void render(SpriteBatch batch, float x, float y, float w, float h) {
    batch.draw(region, x, y, w, h);
}

Where region is a TextureRegion regionTextureRegion

Without the camera, it all works just fine, so I am very confused as to why textures only render in order now (my tile textures are rendered below entities) Does anyone have any idea why this might be? 没有摄像头,一切都很好,所以我对为什么现在仅按顺序渲染纹理感到困惑(我的瓷砖纹理在实体下方渲染)有人知道为什么会这样吗? In case you want to see more code, I also have this on my github: CLICK HERE 如果您想查看更多代码,请在我的github上找到: CLICK HERE

I hadn't realized this later, but I was commenting out a lot of rendering lines, line by line to see if I could find what was wrong, it turns out that my debugging tool I made (which renders collision bounds using a ShapeRenderer ) was messing it up because apparently, a ShapeRenderer cannot be used between a batch.begin and a batch.end 后来我没有意识到这一点,但是我逐行注释了很多渲染线,以查看是否可以找到错误的地方,结果证明我制作了调试工具(使用ShapeRenderer渲染碰撞边界)被搞乱它,因为很显然,一个ShapeRenderer不能之间使用batch.beginbatch.end

I figured this out with the help of this badlogicgames forum post 我在此badlogicgames论坛帖子的帮助下弄清楚了这一点

Can't get much out of the code but are you using this at the root of the render structure? 不能从代码中得到太多好处,但是您是否在渲染结构的根部使用它?

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM