Cocos2d-x—使用TexturePacker对图片进行打包、加密

Cocos2d-x是以2的n次方的内存来加载图片资源的,也就是说如果加载一张80*80的图片,将会消耗128*128的内存,这样会浪费很多内存。这时候就需要一个工具将多张图片拼接成一张大图。TexturePacker就是这样一款工具。下载地址:https://www.codeandweb.com/texturepacker

Cocos2d-x—使用TexturePacker对图片进行打包、加密_第1张图片

Data Format:选择导出游戏引擎支持的数据类型,直接使用默认的cocos2d就可以

Data File:文件保存的路径

Texture Format:图片纹理的数据格式,推荐使用.pvr.ccz

Texture File:纹理图片的路径

Content protection:这个选项是对纹理图片进行加密,点击后会提示输入一个128位的key值(系统可以自动生成)。

使用步骤:

1.直接将图片拖入右边的空白处;

2.填写输出路径

3.点击Geometry->Size constraints,选择NPOT

4.点击Publish输出文件。

5.在cocos2d-x中加载图片,代码如下

[cpp]  view plain copy print ? 在CODE上查看代码片
  1. #include "support/zip_support/ZipUtils.h"  

 

[cpp]  view plain copy print ? 在CODE上查看代码片
  1. //0xa83cca27,0x50f49f7b,0xddbe7d95,0x2b955dd8是将128位的key值分成4部分,每部分32位  
  2.   ZipUtils::ccSetPvrEncryptionKey(0xa83cca27,0x50f49f7b,0xddbe7d95,0x2b955dd8);  
  3.   CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("test.plist""test.pvr.ccz");  
  4.   CCSprite *nonencryptedSprite = CCSprite::createWithSpriteFrameName("grossini.png");  

 转自:http://blog.csdn.net/yifuteli_kevin/article/details/22599853

[cpp]  view plain copy print ? 在CODE上查看代码片
  1. #include "support/zip_support/ZipUtils.h"  

 

[cpp]  view plain copy print ? 在CODE上查看代码片
  1. //0xa83cca27,0x50f49f7b,0xddbe7d95,0x2b955dd8是将128位的key值分成4部分,每部分32位  
  2.   ZipUtils::ccSetPvrEncryptionKey(0xa83cca27,0x50f49f7b,0xddbe7d95,0x2b955dd8);  
  3.   CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("test.plist""test.pvr.ccz");  
  4.   CCSprite *nonencryptedSprite = CCSprite::createWithSpriteFrameName("grossini.png");  

你可能感兴趣的:(C++,Class,cocos2d-x,cocostudio,cocos2d-x3.x)