问题描述
我设法用我拥有的图像打包一个纹理图集,它可以正常工作,因为它会创建 .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 中加载纹理图的区域会加载整个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!