在libgdx中加载textureatlas的区域会加载整个文件 [英] loading regions of textureatlas in libgdx loads the entire file

查看:129
本文介绍了在libgdx中加载textureatlas的区域会加载整个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I managed to pack a textureatlas with images i have and it works properly in that it creates the .pack file and the .png file. The issue is when i load the texture atlas and try to assign AtlasRegions. it loads the entire atlas instead of only the image i want. here is a mockup code i used to test it.

@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();
}

这将渲染整个地图集,而不是仅渲染地图集中称为英雄"的图像.为什么会这样?

this renders the entire atlas instead of only the image called "hero" in the atlas. Why does this happen?

提前谢谢.

推荐答案

操作时.-

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

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

you're actually telling libgdx to render the whole Texture. What you need is to draw just the TextureRegion.-

batch.draw(sprite, 10, 10);

这篇关于在libgdx中加载textureatlas的区域会加载整个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆