【发布时间】:2014-08-20 00:55:41
【问题描述】:
我在 LibGDX 中使用 spriteBatch 绘制 TextureRegions 时遇到了一些问题。
所以我有一个承载游戏逻辑的主类。 在构造函数中,我有:
atlas = new TextureAtlas(Gdx.files.internal("sheet.txt") );
this.loadTileGFX();
loadTileGFX() 方法这样做:
roseFrames = new ArrayList<AtlasRegion>();
roseFrames.add(atlas.findRegion("Dirt", 0));
roseFrames.add(atlas.findRegion("Dirt", 1));
roseFrames.add(atlas.findRegion("Dirt", 2));
roseFrames.add(atlas.findRegion("Dirt", 3));
然后我将 AtlasRegions 的 arrayList 传递给对象:
///in the main class
rsoe = new RoseSquare(roseFrames, st, col, row, tileWidth);
//in the constructor for the object to draw
this.textureRegions = roseFrames;
然后我调用的每个 render() 循环:
batch.begin();
rose.draw(batch);
batch.end()
rose.draw() 方法如下所示:
public void draw(SpriteBatch batch){
batch.draw(this.textureRegions.get(1), rect.x, rect.y, rect.width, rect.height);
}
但问题是,这不会在屏幕上绘制任何内容。
但事情是这样的。 如果我将代码更改为:
public void draw(SpriteBatch batch){
batch.draw(new TextureAtlas(Gdx.files.internal("sheet.txt")).findRegion("Dirt", 0)), rect.x, rect.y, rect.width, rect.height);
}
然后它会正确绘制。 任何人都可以阐明我可能遇到的错误吗? 请注意,“未绘制”代码没有任何错误。 另外,我可以追溯this.textureRegions.get(1)的细节,都是正确的......
谢谢。
【问题讨论】:
-
在第一个方法中,您在第二个 TextureRegion 中渲染 AtlasRegion。我不确定那些是一样的。嗯?
-
这可能是问题所在,但是您在第一个代码中绘制了第二个纹理(在索引
1),但在第二个代码中绘制了第一个纹理(在索引0)。还有@VeljkoAtlasRegion extends TextureRegion -
不,抱歉,这不是问题,我尝试了不同的索引.....hmmmm。
标签: libgdx