-- 转盘总奖项数
local TotalCount = 8
-- 转动最小圈数
local RoundCountMin = 12
-- 转动最大圈数
local RoundCountMax = 12
-- 开始抽奖 stopId 中间区域
function onStartDrawALotteryOrRaffle(stopId)
-- 每个奖项占的角度
local singleAngle = 360 / TotalCount
-- 交界处处理
local offsetAngle = 10
local angleMin = (stopId - 1) * singleAngle
local roundCount = math.random(RoundCountMin, RoundCountMax)
return 360 * roundCount + angleMin + math.random(offsetAngle, singleAngle - offsetAngle)
end
function RotateTurntable(pSprite, inallTime, inallAngle, times, func)
local data = {}
local inallRadian = (inallAngle / 180.0) * math.pi
local offsetTime = inallTime / times
local offsetAngle = inallRadian / (math.atan(inallTime*1.5) - math.atan(-inallTime *0.3))
local startTime = - inallTime *0.3
while (startTime <= inallTime*1.5) do
local angle = (math.atan(startTime + offsetTime) - math.atan(startTime)) * offsetAngle * 180 / math.pi
startTime = startTime + offsetTime
local actionTo = cc.RotateBy:create(offsetTime, angle)
data[#data+1] = actionTo
end
data[#data+1] = func
pSprite:runAction(transition.sequence(data));
end
-- 调用
local angleTotal = onStartDrawALotteryOrRaffle(1) -- stopId = 1 ~ 8
local value = angleTotal - self.spin:getRotationSkewX()
self:RotateTurntable(self.spin, 5, value, 300, cc.CallFunc:create(function()
-- 重置精灵旋转圈数
self.spin:setRotation(angleTotal%360)
end)
转盘游戏代码总结
最新推荐文章于 2024-06-22 21:19:29 发布