【问题标题】:loading regions of textureatlas in libgdx loads the entire file在 libgdx 中加载纹理图的区域会加载整个文件
【发布时间】:2013-11-04 18:08:49
【问题描述】:

我设法用我拥有的图像打包一个纹理图集,它可以正常工作,因为它会创建 .pack 文件和 .png 文件。问题是当我加载纹理图集并尝试分配 AtlasRegions 时。它加载整个图集,而不仅仅是我想要的图像。这是我用来测试它的模型代码。

@Override
public void create() {      
    camera = new OrthographicCamera(800, 480);
    batch = new SpriteBatch();

    test = new TextureAtlas(Gdx.files.internal("polytest.png"));

    sprite = test.findRegion("hero");
    texture = new Texture(Gdx.files.internal("data/libgdx.png"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);


}

@Override
public void render() {      
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    batch.draw(sprite.getTexture(), 10, 10);
    batch.end();
}

这会渲染整个图集,而不仅仅是图集中称为“英雄”的图像。为什么会这样?

提前致谢。

【问题讨论】:

    标签: libgdx


    【解决方案1】:

    当你这样做时。-

    batch.draw(sprite.getTexture(), 10, 10);
    

    您实际上是在告诉libgdx 渲染整个Texture。你只需要画TextureRegion.-

    batch.draw(sprite, 10, 10);
    

    【讨论】:

    • 非常感谢,我整个周末都在苦苦挣扎!不敢相信它是如此简单:O
    猜你喜欢
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多