cocos2d-x抽奖轮盘代码


看到网上有相关抽奖轮盘的实现,刚好自己也在做相关功能,就写了一个,能实现任意个数的抽奖圆盘,上传的GIF帧数有点少(只有10帧),博客不允许大图片没办法,cocos2d-x版本3.3,需要源码资源的可以给我发信息

cocos2d-x抽奖轮盘代码


LuckyRound = class("LuckyRound", function ()

return cc.Layer:create()

end)

function LuckyRound:ctor()

self.bg = cc.Sprite:create("res/luck001.png")

self.bg:setPosition(cc.p(480,320))

self.bg:setAnchorPoint(cc.p(0.5,0.5))

self:addChild(self.bg)

local bgSize = self.bg:getContentSize()



self.pointsBg = cc.Sprite:create("res/luck002.png")

self.pointsBg:setPosition(cc.p(bgSize.width/2,bgSize.height/2))

self.bg:addChild(self.pointsBg)

self.pointsBg:setGlobalZOrder(2)


local centerMarkImg = cc.Sprite:create("res/luck011.png")

centerMarkImg:setPosition(cc.p(bgSize.width/2,bgSize.height/2))

self.bg:addChild(centerMarkImg)


    local selectImg = cc.Sprite:create("res/luck012.png")

    selectImg:setPosition(cc.p(bgSize.width/2,bgSize.height/2+50))

    self.bg:addChild(selectImg)


local actionRotate1 = cc.RotateBy:create(1, 90)

local actionRotate2 = cc.RotateBy:create(1, 360)

local selectedItemNum = 1

local actionRotate3 = cc.RotateBy:create(2, 720)

local actionRotate4 = cc.RotateBy:create(3, 180+20-(selectedItemNum*45))

    local seq = cc.Sequence:create(actionRotate1,actionRotate2,actionRotate3,actionRotate4)

    self.pointsBg:runAction(seq)

    local posList = self:getItemsPos(7,120)

    for i=1,7 do

    local imgSrc = string.format("res/luck0%02d.png", i+2)


    local sprite = cc.Sprite:create(imgSrc)

    sprite:setAnchorPoint(0.5,0.5)

    sprite:setPosition(posList[i].x+166,posList[i].y+166)

    self.pointsBg:addChild(sprite)

    local updateRotate = function ()

    sprite:setRotation(-(self.pointsBg:getRotation()))

    end

    schedule(sprite,updateRotate,0.1)

    end

end

--获取个数,半径为radis 的各个顶点的位置

function LuckyRound:getItemsPos(itemNum,radis)

local e_rot= 2*math.pi/itemNum;

local posList = {}

for i=1,itemNum do

posList[i] = {}

local rot = i*e_rot + 0.5*e_rot;

posList[i].x=radis*math.sin(rot);

posList[i].y=radis*math.cos(rot);

end

return posList

end

return LuckyRound

GIF好像没办法播放!!!!

你可能感兴趣的:(游戏,cocos2d-x,抽奖,轮盘)