1.当打通本关开启下一关卡时增加一个解锁特效,特效播完之后再播放水晶指示特效,其他时候接入地图不播放关卡解锁特效。
if adjustFlag == true or (newChapter == nowChapter and nil ~= lastBtn) then
local x,y = lastBtn:getPosition()
local parent = lastBtn:getParent() –先把父节点保存起来再加特效
if isBattleEnd then --战斗结束播放下一关卡解锁特效
local function addEndEffect()
local jsonPath = "res/effect/300016/skeleton.json"
local atlasPath = "res/effect/300016/skeleton.atlas"
--SkeletonAnimation.new 是前端自己封装的一个接口
local effect = SkeletonAnimation.new(
"new_section_effect",
jsonPath,
atlasPath,
"default",
"animation",
true
)
effect:setPosition(x+0, y-80 + tmpFix)
effect:setScale(1)
parent:addChild(effect._ccnode,100)
SECTION_EFFECT = effect._ccnode
end
local scale = specialEffectScale
local effectId
local effectY = 0
if scale == 1.2 then
effectId = 301005
elseif scale == 1.3 then
effectId = 301006
elseif scale == 1.5 then
effectId = 301007
effectY = 5
end
local resId = SpecialEffectConfig[effectId].resId
local jsonPath = "res/effect/"..resId.."/skeleton.json"
local atlasPath = "res/effect/"..resId.."/skeleton.atlas"
local effect = SkeletonAnimation.new(
"jie_suo_effect",
jsonPath,
atlasPath,
"default",
"animation",
false
)
effect:setPosition(x, y - effectY)
effect:setScale(SpecialEffectConfig[effectId].scaleNum)
effect:setTimeScale(SpecialEffectConfig[effectId].scaleTime)
parent:addChild(effect._ccnode,10)
local function actionEnd(event)
if "complete" == event.type then
effect:unregisterSpineEventHandler(sp.EventType.ANIMATION_COMPLETE) --播完要把这个事件的监听取消掉
addEndEffect()
end
end
effect:registerSpineEventHandler(actionEnd, sp.EventType.ANIMATION_COMPLETE)
else
local jsonPath = "res/effect/300016/skeleton.json"
local atlasPath = "res/effect/300016/skeleton.atlas"
local effect = SkeletonAnimation.new(
"new_section_effect",
jsonPath,
atlasPath,
"default",
"animation",
true
)
effect:setPosition(x+0, y-80 + tmpFix)
effect:setScale(1)
parent:addChild(effect._ccnode,100)--因为x,y是相对于地图的坐标,而特效的坐标也是相对于地图而言的,所以是将特效添加到地图上而不是添加到关卡的按钮上
SECTION_EFFECT = effect._ccnode
end
end
2.给主界面的闪亮大礼包图标添加闪亮的特效
function updateActivityButton(self)
local layer = self._ccnode:getChildByName(“activityPanel”)
local buttonFlex = layer:getChildByName(“shensuo”)
local playerLevel = PlayerInfo.getLv()
local playerVip = PlayerInfo.getVip()
self.activity.activities = {}
for i, config in ipairs(MainpageConfig.ActivityConfig) do
if config.posIndex == ActivityLogic.posIndex.homepage then
local isShowFuncName = isShowActivityFuncNames[config.activity]
local isShow = true
repeat
if playerLevel < config.levelLimit or playerVip < config.vipLimit then
isShow = false
break
end
if isShowFuncName and self[isShowFuncName] then
isShow = isShow and self[isShowFuncName](self)
end
until true
if isShow then
table.insert(self.activity.activities, config.activity)
table.insert(self.activity.special,config.activity)
end
end
end
local buttonNum = #self.activity.buttons
local activityNum = #self.activity.activities
if buttonNum > activityNum then
for i = 1, buttonNum -activityNum do
local button = table.remove(self.activity.buttons)
button:removeFromParent()
end
elseif buttonNum < activityNum then
for i = 1, activityNum - buttonNum do
local button = self.activity.moduleActivity:clone()
layer:addChild(button)
table.insert(self.activity.buttons, button)
end
end
local positonFlexX, positonFlexY = buttonFlex:getPosition()
local effecName = "effect"
for i, button in ipairs(self.activity.buttons) do
local activity = self.activity.activities[i]
local activityConfig = HomepageActivityConfig[activity]
--因为不知道之前需要去掉特效的图标位置变化成了多少,所以每个图标都要检查一下,把所有图标的特效都去掉再根据条件加特效。
local effect = button:getChildByName(effecName)
if effect then
effect:removeFromParent(true)
end
if self.activity.isFlex then
local imageMark = button:getChildByName("hongdian")
local row = math.ceil((i + 1) / self.activity.maxCol)
local col = i + 1 - (row - 1) * self.activity.maxCol
button:setPosition(positonFlexX - self.activity.intervalWidth * (col - 1), positonFlexY - self.activity.intervalHeight * (row - 1))
button:setVisible(true)
button:loadTextureNormal(string.format(MainpageConfig.pathActivityButton, activityConfig.resource))
local function onButton(sender, eventType)
if eventType == ccui.TouchEventType.ended then
local funcName = activityButtonFuncNames[activity]
if funcName and self[funcName] then
self[funcName](self)
end
end
end
button:addTouchEventListener(onButton)
local markFunc = markActivityFuncNames[activity]
if markFunc and self[markFunc](self) then
imageMark:setVisible(true)
else
imageMark:setVisible(false)
end
button:setVisible(true)
--添加图标的特效
local specialFunc = isShowActivitiesSpecialFuncNames[activity]
local effectId = activityConfig.effectId
if specialFunc and self[specialFunc](self) and effectId ~= "" then
local scale = button:getScale()
local jsonPath = "res/effect/"..effectId.."/skeleton.json"
local atlasPath = "res/effect/"..effectId.."/skeleton.atlas"
local effect = SkeletonAnimation.new(
effecName,
jsonPath,
atlasPath,
"default",
"animation",
true
)
effect:setPosition(60, 0)--因为effect是button的子节点,所以这里设置是相对父节点的位置。如果这个特效的位置取的button的x,y设进去,x,y是个比较大的值的话,会抛出屏幕的外面看不到特效!
effect:setScale(scale)
effect._ccnode:setName(effecName)
--前面有说过SkeletonAnimation.new是自己封装的接口,虽然effect._name==effecName,但还是要用原生态的接口setName()设置下节点的名字,要不然前面local effect = button:getChildByName(effecName) 移除特效的时候会找不到刚才设置的特效。
button:addChild(effect._ccnode,1)
end
else
button:setVisible(false)
end
end
end
3.上下滑动副本地图可以跳转章节,即在地图处于最底部或最顶部时,向上滑动地图或向下滑动地图可进入上一章节或下一章节
local function scrollViewEvent(sender, evenType)
if evenType == ccui.ScrollviewEventType.scrollToBottom then
self._toBottomCount = self._toBottomCount + 1
if self._toBottomCount >= 6 then
local chapterId = self._charpterId - 1
if chapterId >= 1 then
local chapters = CampaignInfo.getChapters()
local sections = chapters[chapterId].sections
if next(sections) ~= nil then
local function doOpenUi()
Campaign.showChapter(chapterId, sections)
end
performWithDelay(Stage.currentScene._ccnode, doOpenUi, 0.02)
end
end
end
elseif evenType == ccui.ScrollviewEventType.scrollToTop then
self._toTopCount = self._toTopCount + 1
if self._toTopCount >= 8 then --因为已经通关的章节一进去就自动滚到最顶端,所以这里要加个计数,要不然会一直跳到没有通关的章节
local chapters = CampaignInfo.getChapters()
local chapterId = self._charpterId + 1
if chapterId < #chapters then
local condition = chapters[chapterId].condition
local isReach = CampaignInfo.checkCondition(condition)
if condition and CampaignInfo.checkCondition(condition) then
local sections = chapters[chapterId].sections
if next(sections) ~= nil then
local function doOpenUi()
Campaign.showChapter(chapterId, sections)
end
performWithDelay(Stage.currentScene._ccnode, doOpenUi, 0.02)
end
end
end
end
end
end
4.如何传递self
function initUI(self)
local downBaseBg = self._ccnode:getChildByName(“downBaseBg”)
local mainBtn = downBaseBg:getChildByName(“mainBtn”)
local roleBtn = downBaseBg:getChildByName(“roleBtn”)
local heroBtn = downBaseBg:getChildByName(“heroBtn”)
local bagBtn = downBaseBg:getChildByName(“bagBtn”)
local friendBtn = downBaseBg:getChildByName(“friendBtn”)
local shopBtn = downBaseBg:getChildByName(“shopBtn”)
heroBtn._self = self
roleBtn._self = self --把self给存起来
mainBtn:addTouchEventListener(onMainBtn)
roleBtn:addTouchEventListene
end
function onRoleBtn(sender, eventType)
if ccui.TouchEventType.ended == eventType then
PartnerLogic.setIsRoleMark(false)
updateMarkRole(sender._self) –使用刚才的self
CharacterPort.goToCharacterUI()
end
end
function updateMarkRole(self)
……
end