本文介绍了libgdx spritebatch不渲染纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LibGDX做一个自上而下的RPG游戏,我正在为我的游戏创建一个Ortho ..摄像机。然而,在这样做,只有我的瓷砖纹理渲染。这是渲染代码的外观:

I'm working on a top down RPG game using LibGDX, and am creating an Ortho.. camera for my game. However in doing so, only my tile textures render now. This is how the render code looks:

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

(请注意 camera。调用实际上在 world.update 方法,我只是想我会尽量减少代码需要在这里)

(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)

更新/渲染: / p>

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:

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

其中 region a TextureRegion

没有相机,这一切都很好,所以我很困惑为什么纹理现在渲染(我的瓦片纹理渲染下面的实体)有谁有任何想法为什么这可能是?如果你想看到更多的代码,我也在我的github:

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

推荐答案

我以前没有意识到这一点,但我注释了很多渲染线,看看我是否能找到什么错误,事实证明我的调试工具(使用 ShapeRenderer 渲染碰撞边界)弄乱了,因为显然,一个<$不能在 batch.begin batch.end ShapeRenderer >

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

我想通过

这篇关于libgdx spritebatch不渲染纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 22:12
查看更多