新做一个转盘的抽奖活动。
由于刚接触cocos不是很久,也在网上看了一些别人的实现。
大概的思路:先设计好各种中奖的概率(貌似是服务器的事),前端在收到中奖消息时只是展示。
local function clampAngel(angel)
while angel > 360 do
angel = angel - 360end
while angel <0 do
angel = angel + 360
end
return angel % 360
end
local rotateTable={ --这就是各种中奖的角度,假定每个为36度
{startPost= 0,endP = 36},
{},
。。。
}
local offset = 5 --定义一个偏移,避免停留在交界处
self.currentRotate = 0 --当前的角度值
local rotateNum = MathUtil.random(4, 8) --随机的旋转的圈数
local rotate = clampAngel(MathUtil.random(rotateDate[currentIndex].startP + offset,rotateDate[currentIndex].endP - offset ) - self.currentRotate + 360)
self.currentRotate = clampAngle(rotate + self.currentRotate) --更新旋转后自己的角度,连