LibGdx中的textureregion和atlasregion有什么区别?
What is the difference between textureregion and atlasregion in LibGdx?
我想知道有什么区别。还有人能说说texture和textureatlas的区别吗
格雷茨·吕克
当您通过 Texture t = new Texture("");
在游戏中加载纹理时,您在 GPU 中加载了纹理。
TextureRegion,根据你提供的维度从Texture中取一块区域,有它的好处是你不用反复加载纹理,更大的好处是你不用加载GPU 上的每个纹理,因为您可以直接通过加载一个大纹理并从中提取子区域 (TextureRegions) 来完成。
现在因为要使用 TextureRegions
,所以很难知道每个子图像的尺寸以从纹理 Sheet 加载它们。所以我们所做的是使用 TexturePacker(一个应用程序)将纹理打包成一个更大的纹理,然后创建一个 .pack
文件。它会将每个纹理打包到一个图像中并创建一个 .pack 文件。现在,当您加载 .pack 文件时,它是使用 TextureAtlas
class 加载的
例如,想象一个包含所有口袋妖怪的口袋妖怪包文件。
TextureAtlas pokemonFrontAtlas = new TextureAtlas(Gdx.files.internal("pokemon//pokemon.pack"));
现在假设您使用 Texture Packer 打包了 100 个文件,并且您想要加载文件名为 "SomePokemon".
的图像 (Texture
)
现在要从中获取特定的 TextureRegion,您可以
pokemonFrontAtlas.findRegion("SomePokemon")
findRegion(String name) returns 你从 TextureAtlas
.
的 textureRegion
总而言之,主要区别在于,TextureRegion
是来自纹理的区域,而 TextureAtlas
是 TextureRegions
的集合。
编辑
A TextureAtlas
class 包含 AtlasRegion
class 的集合,它扩展了 TextureRegion
class.
有关详细信息,请参阅 Javadocs
TextureAtlas
- A
Texture
是 OpenGL 2D 纹理的 libGDX 实现。即:它表示GPU内存中的单个2D纹理,可用于渲染。您通常希望使用尽可能少的纹理(特别是希望避免在纹理之间切换)。因此,通常将多个图像包含在一个更大的 Texture
. 中
- 一个
TextureRegion
用来定义一个Texture
的区域。实际上它是这样说的:"on that texture at those coordinates and those dimensions this image is located".
- A
TextureAtlas
是一个或多个 Texture
及其包含的区域的容器。您通常会从包含有关地图集的所有信息的文件中加载 TextureAtlas
。此文件通常使用 TexturePacker
工具创建。请注意,一个图集可以包含多个纹理文件。
- A
AtlasRegion
是一个 TextureRegion
,其中包含有关包装的附加信息。例如。当区域旋转以获得最佳包装时,AtlasRegion
包含此信息,因此它知道在绘制时必须撤消该操作。同样,如果您在打包图集时使用了空白剥离以获得更紧密的打包,则 AtlasRegion
包含再现原始图像所需的信息。
我想知道有什么区别。还有人能说说texture和textureatlas的区别吗
格雷茨·吕克
当您通过 Texture t = new Texture("");
在游戏中加载纹理时,您在 GPU 中加载了纹理。
TextureRegion,根据你提供的维度从Texture中取一块区域,有它的好处是你不用反复加载纹理,更大的好处是你不用加载GPU 上的每个纹理,因为您可以直接通过加载一个大纹理并从中提取子区域 (TextureRegions) 来完成。
现在因为要使用 TextureRegions
,所以很难知道每个子图像的尺寸以从纹理 Sheet 加载它们。所以我们所做的是使用 TexturePacker(一个应用程序)将纹理打包成一个更大的纹理,然后创建一个 .pack
文件。它会将每个纹理打包到一个图像中并创建一个 .pack 文件。现在,当您加载 .pack 文件时,它是使用 TextureAtlas
class 加载的
例如,想象一个包含所有口袋妖怪的口袋妖怪包文件。
TextureAtlas pokemonFrontAtlas = new TextureAtlas(Gdx.files.internal("pokemon//pokemon.pack"));
现在假设您使用 Texture Packer 打包了 100 个文件,并且您想要加载文件名为 "SomePokemon".
的图像 (Texture
)
现在要从中获取特定的 TextureRegion,您可以
pokemonFrontAtlas.findRegion("SomePokemon")
findRegion(String name) returns 你从 TextureAtlas
.
总而言之,主要区别在于,TextureRegion
是来自纹理的区域,而 TextureAtlas
是 TextureRegions
的集合。
编辑
A TextureAtlas
class 包含 AtlasRegion
class 的集合,它扩展了 TextureRegion
class.
有关详细信息,请参阅 Javadocs TextureAtlas
- A
Texture
是 OpenGL 2D 纹理的 libGDX 实现。即:它表示GPU内存中的单个2D纹理,可用于渲染。您通常希望使用尽可能少的纹理(特别是希望避免在纹理之间切换)。因此,通常将多个图像包含在一个更大的Texture
. 中
- 一个
TextureRegion
用来定义一个Texture
的区域。实际上它是这样说的:"on that texture at those coordinates and those dimensions this image is located". - A
TextureAtlas
是一个或多个Texture
及其包含的区域的容器。您通常会从包含有关地图集的所有信息的文件中加载TextureAtlas
。此文件通常使用TexturePacker
工具创建。请注意,一个图集可以包含多个纹理文件。 - A
AtlasRegion
是一个TextureRegion
,其中包含有关包装的附加信息。例如。当区域旋转以获得最佳包装时,AtlasRegion
包含此信息,因此它知道在绘制时必须撤消该操作。同样,如果您在打包图集时使用了空白剥离以获得更紧密的打包,则AtlasRegion
包含再现原始图像所需的信息。