我正在创建两个纹理并将它们放在同一个 TextureAtlas 中,如代码所示:
public void create () {
pix = new Pixmap(100, 100, Pixmap.Format.RGBA8888);
textureAtlas = new TextureAtlas();
pix.setColor(Color.WHITE);
pix.fill();
textureAtlas.addRegion("white", new TextureRegion(new Texture(pix)));
pix.setColor(Color.RED);
pix.fill();
textureAtlas.addRegion("red", new TextureRegion(new Texture(pix)));
tr_list = textureAtlas.getRegions();
pix.dispose()
}
然后在渲染时:
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
for (int i = 0; i < 200; ++i) {
batch.draw(tr_list.get(i % tr_list.size), (int)(Math.random()* 500), (int)(Math.random()* 500));
}
font.draw(batch, "FPS: " + Integer.toString(Gdx.graphics.getFramesPerSecond()), 0, Gdx.graphics.getHeight() - 20);
font.draw(batch, "Render Calls: " + Integer.toString(batch.renderCalls), 0, Gdx.graphics.getHeight() - 60);
batch.end();
}
我期望 batch.renderCalls 等于 1,因为纹理在同一个 TextureAtlas 中,但它等于 200。我做错了什么?