1.v.text = string.sub(v.text,7,-1)--去掉buff的名字,例如:v.text = 攻击#C(#00EE00)+%s,这时候要去掉前面的攻击2字,用string.sub,但是起始位置是7,因为一个中文占3个字节。
2.
如图,pageview翻页除了用手指滑动,还可以实际左右两个翻页按钮,但是要做好按钮灰化的同步。可以监听翻页事件,然后在事件里面做同步。
local function pageViewEvent(sender, eventType)
if eventType == ccui.PageViewEventType.turning then
self:refreshBtns()
end
end
pageView:addEventListener(pageViewEvent)
3.在播放技能特效时,如果刚好技能放完怪物就死了,而特效配错了有2个trigger,那么在第二个trigger的时候会找不到目标而报错。
-- 播放特效
function Fight:playEffectArmature(effectName, flipH, x, y, z, z2, finishCallBack, triggerCallBack)
local effectArmature = EffectArmature.new(effectName, z, z2)
effectArmature:setActionManager(self.actionManager)
effectArmature:setScheduler(self.scheduler)
effectArmature:setPosition(x, y)
effectArmature:addParent(self)
if flipH then
effectArmature:setScaleX(-1)
end
effectArmature:play(0)
local function onFrameEvent( bone,evt,originFrameIndex,currentFrameIndex)
if triggerCallBack then
triggerCallBack()--特效帧中的trigger会触发到这里
end
end
local function animationEvent(armatureBack, movementType, movementID)
if movementType == ccs.MovementEventType.complete then --特效播完的回调
effectArmature:removeFromParent()
if finishCallBack then
finishCallBack()
end
end
end
effectArmature:setFrameEventCallFunc(onFrameEvent)
effectArmature:setMovementEventCallFunc(animationEvent)
return effectArmature
end
3.lua中三角函数的使用,math.sin(x),x是表示弧度,所以要表示sin60,要先把角度转为弧度,math.rad(60),整个为math.cos(math.rad(60))
4.当一个按钮点击之后一直显示点击状态,不是用setBright(设置高亮),而是用loadTextureNormal,如:
if self.autoFlag then
self.autoFlag = false
self.rightView.autoBtn:loadTextureNormal("res/ui/Resources/Btn/btn_lanse.png",ccui.TextureResType.localType)
else
self.autoFlag = true
self.rightView.autoBtn:loadTextureNormal("res/ui/Resources/Btn/btn_lanse_p.png",ccui.TextureResType.localType)
end
5.加载图片资源时,如果路径错了是不会报错的,只有在路径名对,但是有个别字母大小写不对的时候3.11才会有提示信息(3.3没提示,都能正常显示)
如:imageModel:loadTexture("ui/Resources/ico/tank.png",ccui.TextureResType.localType) --正确路径
如果写成imageModel:loadTexture("ui/Resources/common/ico/tank.png",ccui.TextureResType.localType)或者
imageModel:loadTexture("ui/Resources/icoo/tank.png",ccui.TextureResType.localType) 是不会有提示信息的,如果写成
imageModel:loadTexture("ui/Resources/iCo/tank.png",ccui.TextureResType.localType) 有
File path error: "G:/prj_t/code/client/project/res/ui/Resources/iCo/tank.png" the real name is: ico/tank.png 的提示。