在这里实现一个简单的转盘效果供大家参考:
local index = math.random(1,5)
local degree = 360 - (index - 1) * 120 + 360 * 3
local action1 = cc.EaseSineIn:create(cc.RotateBy:create(1, 360))
local action2 = cc.EaseSineOut:create(cc.RotateBy:create(2, degree))
self.zhuanpan:runAction(cc.Sequence:create(cc.DelayTime:create(2),action1,action2,
cc.CallFunc:create(function ()
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.myScheduler)
end)))
if nil ~= self.myScheduler then
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.myScheduler)
end
local angle1 = 0
local angle2 = self.zhuanpan:getRotation()
local function callback()
local angle2 = self.zhuanpan:getRotation()
if angle3 - angle2 >= angle1 then
angle1 = angle1 + 120
end
end
local scheduler = cc.Director:getInstance():getScheduler()
self.myScheduler = scheduler:scheduleScriptFunc(callback, 1/60, false)
|