cocos-Lua个人小积累


1)在登录过程中,客户端这边发一个密码转换的md5值,之后发给服务端,服务端进行有无这个玩家的查询,以及密码的匹配,一致就发送登录成功的消息
加密函数如下:
MD5_CTX:MD5String(psw) 通过这行代码把psw加密成md5值


2)触摸事件:

在设置整个层的触摸事件,还有按钮的点击事件的时候,我就在想,如果我设置这个按钮外的范围的层触摸隐藏其他位置的四个按钮,那样,我点击其他四个按钮的时候会发生什么呢?是响应该按钮的点击事件,还是隐藏该四个按钮呢?

其实,在这个过程中,涉及到了一个触摸事件的优先级,在同一个层中,按钮的点击事件是优先于层的触摸事件的

在优先级相同的情况下,后添加的事件先响应


3)创建Lua新项目:

cocos new TestGame -p com.mygame.test -l lua -d D:\Lua\Luatest


4)CheckBox复选框

CheckBox在Cocos Studio为复选框,可以设置选中状态与取消状态,选中状态显示标识样式中的正常状态,取消则显示背景样式

Lua中eventType 为ccui.CheckBoxEventType.selected 与 ccui.CheckBoxEventType.unselected


5)判断背景音乐是否已经播放完,在cocos2dx的音效引擎中有如下的接口

cc.SimpleAudioEngine:getInstance():isMusicPlaying()

可以让我们判断背景音乐是否在播放


6)添加安卓横屏基于重力感应

在安卓打包时的AndroidManifest.xml文件中设置,把android:screenOrientation设置为"sensorLandscape"即可,其为横屏重力感应


7)

imageView->ignoreContentAdaptWithSize(false);
//如果设置为true,忽略内容适应,使用系统默认的渲染大小,与实际的图片资源大小无关

8)static OrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);

     --创建一个轨道摄像机动作  
     -- t:动作的执行时间  
     -- radius:起始半径  
     --deltaRadius:半径增量  
     -- angleZ:起始Z轴角度  
     -- detaAngleZ: Z轴角度的增量  
     -- angleX:起始X轴角度  
     -- deltaAngleX:X轴角度的增量

8)获取随机字母

function tools.getRandomStr(digit)
local t = 
{
"0","1","2","3","4","5","6","7","8","9",
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"
};
local str = ""
math.randomseed(os.time())
for i=1, digit do
str = str..t[math.random(#t)]
end
return str
end

你可能感兴趣的:(Lua)