一个环绕倒计时效果,直接上代码:
--[[倒计时类start 开始倒计时stop 终止倒计时--]]local CountDown = class("CountDown",function() return cc.Node:create()end)CountDown._Timer = nilCountDown._Start = 0CountDown._End = 100CountDown._Duration = 0CountDown._EndCallback = nil--[[ressprite 倒计时资源duration 倒计时时间,默认0st 开始百分比,默认0ed 结束百分比,默认100endCallback 回调,stop时调用--]]function CountDown:create(ressprite,duration,st,ed,endCallback) return CountDown.new(ressprite,endCallback)endfunction CountDown:ctor(ressprite,endCallback) if st ~= nil then self._Start = st end if ed ~= nil then self._End = ed end self._Timer = cc.Progresstimer:create(ressprite) self._Timer:setType(cc.PROGRESS_TIMER_TYPE_RADIAL) self._Timer:setposition(cc.p(0,0)) -- 0-->100 动画方向 逆时针 self._Timer:setReverseDirection(true) -- 设置中心点 -- self._Timer:setMIDpoint(cc.p(0.25,0.5)) self._Timer:setVisible(false) self:addChild(self._Timer) self._Duration = duration self._EndCallback = endCallbackendfunction CountDown:start( time ) if time == nil then time = self._Duration end self:stop(false,false) self._Timer:runAction( cc.Sequence:create( cc.CallFunc:create( function( sender ) self._Timer:setVisible(true) end),cc.ProgressFromTo:create(time,self._Start,self._End),cc.CallFunc:create( function( sender ) self:stop() end) ) )endfunction CountDown:stop( isHIDe,isCallback ) if isHIDe == nil then isHIDe = true end if isCallback == nil then isCallback = true end self._Timer:stopAllActions() if isHIDe then self._Timer:setVisible(false) end if isCallback and self._EndCallback ~= nil then self._EndCallback() endendreturn CountDown
local timer = cc.Sprite:create("test.png") CountDown = require("CountDown") local cd = CountDown:create(timer,10,100,function ( ) print("CountDown end!=========") end) cd:setposition(cc.p(250,400)) rootLayer:addChild(cd) cd:start()
总结
以上是内存溢出为你收集整理的【cocos2dx 3.3 lua】05 环绕倒计时效果全部内容,希望文章能够帮你解决【cocos2dx 3.3 lua】05 环绕倒计时效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)