本文章讲述利用cocos2d-x 开发手机游戏的一些加密心得。如有问题,请多指正。
更多信息详见:http://blog.csdn.net/chengyingzhilian/article/details/25540441
本文地址:http://blog.csdn.net/chengyingzhilian/article/details/25076419
关于图片资源的打包当然是采用TexturePacker了。官方网址:http://www.codeandweb.com/texturepacker
个人觉得是2d里面最好的资源打包工具,没有之一。
TexturePacker它是一款把若干资源图片拼接为一张大图的工具。TexturePacker可以直接选定一个文件夹,将里面的小图片生成一个大图片,并输出plist文件的工具。使用该工具,合图就非常简单了。TexturePacker自带有资源加密的功能。
关于如何使用。在此不再赘述。可自行搜索教程。
在此只想说明两点网上很少提及的:
1.命令行。
2.加密。
You can specify one or more .png or .tps files or directories for processing.
<folder> Recursively adds all known files in the sprite sheet
<*.tps> *.tps file created with TexturePackerPro (requires pro license)
Additional set options override settings in the *.tps file
<*.swf> Flash requires pro license
<images> Image formats, supported:
Output:
--sheet <filename> Name of the sheet to write, see texture-format for formats available
--texture-format <id> Sets the format for the textures.
The format type is automatically derived from the sheet‘s file name
if possible.
--data <filename> Name of the data file to write
--format <format> Format to write, default is cocos2d
--force-publish Ignore smart update hash and force re-publishing of the files
--texturepath <path> Adds the path to the texture file name stored in the data file.
Use this if your sprite sheets are not stored in another folder than your data files.
--reduce-border-artifacts Removes dark shadows around sprites
--extrude <int> Extrudes the sprites by given value of pixels to fix flickering problems in tile maps
--scale <float> Scales all images before creating the sheet. E.g. use 0.5 for half size
--scale-mode <mode> Use mode for scaling:http://www.codeandweb.com/texturepacker/contentprotection
不过,cocosBuilder作者已经不再维护Builder了。所以教程对应的cocos2d 2.x 有些过时。所以在此重新啰嗦一下.
首先看一下,资源包加密VS未加密预览的效果:
你需要填写32位的密钥(0-9 a-f)
2.Save
3.Publish
接下来的步骤和官方的介绍不同:主要是3.0已经集成了图片加密的功能。
首先需要了解:
如果你的密钥是aaaaaaaabbbbbbbbccccccccdddddddd,你必须将它们分成4部分每部分8位:
0xaaaaaaaa
0xbbbbbbbb
0xcccccccc
0xdddddddd
在TexturePacker官网介绍的方法是下载其提供的ZipUtils 文件替换cocos2dx 。在最新版的cocos2dx zipUtils 里面已经集成了对TexturePacker 解密的处理,所以无需按照其步骤处理。cocos2dx/support/zip_support/ZipUtils.h
/** Sets the pvr.ccz encryption key.
*
* Example: If the key used to encrypt the pvr.ccz file is
* 0xaaaaaaaabbbbbbbbccccccccdddddddd you will call this function with
* the key split into 4 parts as follows
*
* ZipUtils::ccSetPvrEncryptionKey(0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd);
*
* Note that using this function makes it easier to reverse engineer and
* discover the complete key because the key parts are present in one
* function call.
*
* IMPORTANT: Be sure to call ccSetPvrEncryptionKey or
* ccSetPvrEncryptionKeyPart with all of the key parts *before* loading
* the spritesheet or decryption will fail and the spritesheet
* will fail to load.
*
* @param keyPart1 the key value part 1.
* @param keyPart2 the key value part 2.
* @param keyPart3 the key value part 3.
* @param keyPart4 the key value part 4.
*/
static void ccSetPvrEncryptionKey(unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3, unsigned int keyPart4); Ps: 在ZipUtils 中还有其他类似的函数。使用其中一个即可。我们在AppDelegate.cpp applicationDidFinishLaunching函数中增加如下代码:
ZipUtils::ccSetPvrEncryptionKey(0x12345678,0x87654321,0x12345678,0x87654321);
就可以正常使用资源了。
require "Cocos2d"
cclog = function(...)
print(string.format(...))
end
-- for CCLuaEngine traceback
function __G__TRACKBACK__(msg)
cclog("----------------------------------------")
cclog("LUA ERROR: " .. tostring(msg) .. "\n")
cclog(debug.traceback())
cclog("----------------------------------------")
end
local function createShowSpriteScene()
cc.SpriteFrameCache:getInstance():addSpriteFrames("files/sprite.plist")
local showSprite = cc.Sprite:createWithSpriteFrameName("success_1.png")
showSprite:setPosition(cc.p(200,200))
return showSprite
end
local function main()
-- avoid memory leak
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)
local scene = cc.Scene:create()
local layer = createShowSpriteScene()
scene:addChild(layer)
cc.Director:getInstance():runWithScene(scene)
end
xpcall(main, __G__TRACKBACK__)
手机游戏加密那点事儿_2d资源加密_1,布布扣,bubuko.com
原文:http://blog.csdn.net/chengyingzhilian/article/details/25076419