cocos2dx上如何对图片和文字做倒影(镜像)效果

由于工作中需要对图片和文字做镜像效果,开始的时候也是一头雾水,不知道怎么做,后来自己上网查资料,最后发现cocos2dx提供的方法,可以做镜像或者倒影的效果;


对于图片做倒影效果:就是声明一个同样的sprite,这个新的sprite对y轴翻转就是效果了,是不是好简单;
Sprite * bgSprite = Sprite::create("fixbg.png");
bgSprite->setPosition(100.0, 70.0);
this->addChild(bgSprite, 0);
Sprite * bgReflectionSprite;
//下面是倒影的sprite
Sprite * bgReflectionSprite = Sprite::create("fixbg.png");
bgReflectionSprite->setFlippedY(true);//Y轴翻转
bgReflectionSprite->setOpacity(20);//设置透明度
bgReflectionSprite->setPosition(100, 70.0 - bgReflectionSprite->getContentSize().height - 15);//设置位置
this->addChild(bgReflectionSprite, 0);
对于文字的镜像效果:
由于文字并不是图片,在网上开始找方法,发现可以使用LabelTTF和使用sprite一样的方式,实现倒影,但是我在我的pc板子上可以出现倒影,跑到我的linux板子上就无法显示,为这找了半天都没有找到原因,由于我使用的是cocos2dx3
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A:在cocos2dx中,可以通过加密lua代码和图片资源来保护项目的安全性。下面是一些简单的步骤来加密和解密lua代码和图片资源: 1. 加密Lua代码 可以使用luajit来编译Lua代码,然后使用gzip压缩和base64编码来加密Lua代码。以下是使用此方法加密Lua代码的示例代码: ``` local status, bytecodes = pcall(function() local bytecodeStream = io.popen("luajit -bg myScript.lua -") local bytecode = bytecodeStream:read("*all") bytecodeStream:close() return bytecode end) if not status then error(bytecodes) end local compressed = zlib.compress(bytecodes, 9) local cipher = mime.b64(compressed) ``` 2. 加密图片资源 可以使用图片加密工具,如TexturePacker,将图片打包成一个txp包。然后可以使用AES加密算法来加密txp包,以下是使用此方法加密图片资源的示例代码: ``` local Crypto = require "crypto" local data = cc.FileUtils:getInstance():getDataFromFile("myImage.txp") local iv = Crypto.digest("sha256", "mySecretKey", true) local key = Crypto.digest("md5", "mySecretKey", true) local encrypted = Crypto.encryptAES256(data, key, iv) cc.FileUtils:getInstance():writeDataToFile(encrypted, "myImageEncrypted") ``` 3. 解密Lua代码 可以使用base64解码和gzip解压缩函数解密加密的Lua代码,然后使用loadstring函数来运行解密后的代码。以下是使用此方法解密Lua代码的示例代码: ``` local cipher = "..." local compressed = mime.unb64(cipher) local bytecodes = zlib.decompress(compressed) local f = loadstring(bytecodes) f() ``` 4. 解密图片资源 使用AES解密算法来解密加密的图片资源。以下是使用此方法解密图片资源的示例代码: ``` local Crypto = require "crypto" local encrypted = cc.FileUtils:getInstance():getDataFromFile("myImageEncrypted") local iv = Crypto.digest("sha256", "mySecretKey", true) local key = Crypto.digest("md5", "mySecretKey", true) local decrypted = Crypto.decryptAES256(encrypted, key, iv) cc.FileUtils:getInstance():writeDataToFile(decrypted, "myImage") ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值