第十三章:图片资源打包器(TexturePacker)

2018-08-03  本文已影响115人  xiaolei123

TexturePacker介绍

1.介绍:TexturePacker 是一款把若干张资源图片拼接为一张大图的工具。
2.特点:
- 1.提高载入速度
把小图拼接成一张大图,一次载入,减少IO,提高速度
- 2. 减少内存
OpenGL ES 纹理的宽高都是需要2次幂数,在加入内存后,使用TexturePacker 打包后,它会变成一张512*512的纹理,进而减少了内存的使用。
- 3. 加快渲染速度
OpenGl ES 渲染图片,是需要使用glDrawaArray ,一张纹理调用一次,将所有纹理使用TexturePacker打包后,会减少glDrawArray的使用,进而加快渲染速度。

TexturePacker 下载使用

下载地址:https://gitee.com/xcode_xiao/LibGdxDemos2/raw/master/gdx-texturepacker.jar

原素材:


原素材

打包后:


打包后

TextureAtlas

API定义:TexturePacker封装的一个类,用于加载TexturePacker打包的图片。

功能用途:

public TextureAtlas (FileHandle packFile, FileHandle imagesDir, boolean flip) 

第一个参数:传入pack文件
第二个参数:图片路径
第三个参数:是否翻转

常用方法:

提示:

public class AtlasRegion extends TextureRegion 

pack文件格式

texture_pack.png // 对应图片
format: RGBA8888
filter: Nearest,Nearest
repeat: none
shujia
  rotate: false
  xy: 1, 129
  size: 508, 370
  orig: 508, 370
  offset: 0, 0
  index: -1 // 索引
success_bg//名称
  rotate: false
  xy: 511, 255
  size: 259, 244
  orig: 259, 244
  offset: 0, 0
  index: -1// 索引

运行图片:


运行图片

DEMO地址:https://gitee.com/xcode_xiao/LibGdxDemos2/tree/master/TexturePackerDemo

上一篇 下一篇

猜你喜欢

热点阅读