diff --git a/TurntableDemo/README.md b/TurntableDemo/README.md index d942874..09b0019 100644 --- a/TurntableDemo/README.md +++ b/TurntableDemo/README.md @@ -1,2 +1,2 @@ -# 转盘demo -一个简单实现的转盘demo +# hello-world +Hello world new project template. diff --git a/TurntableDemo/assets/Script/TurntableMgr.js b/TurntableDemo/assets/Script/TurntableMgr.js index 04af44e..28f4172 100644 --- a/TurntableDemo/assets/Script/TurntableMgr.js +++ b/TurntableDemo/assets/Script/TurntableMgr.js @@ -3,10 +3,10 @@ cc.Class({ properties: { nodeBoxBg: cc.Node, - total: 6,//几项 - section: 0,//一项分多少 - resultIdx: 0, - delayTime: 0, + total: 6,//几项奖品 + section: 0,//一项奖品切多少份 + resultIdx: 0,//显示的结果id + delayTime: 0,//延期多少才开始显示结果 }, initProperties() { @@ -49,9 +49,27 @@ cc.Class({ this.node.runAction(cc.sequence(cc.delayTime(1 + this.delayTime), cc.callFunc(() => { console.log('已经选择了'); this.choiceIdx = (this.total - this.resultIdx) * this.section; + this.choiceIdx = this.randomChoiceIdx(this.choiceIdx); }))); }, + onFinish() { + console.log('结束了'); + }, + + randomChoiceIdx(idx) { + console.log('randomChoiceIdx'); + let randomIdx = Math.floor(Math.random() * (this.section - 1)); + if (randomIdx == 0) {//不能是上边 + randomIdx++; + } else if (randomIdx == this.section) {////不能是下边 + randomIdx--; + } + let temp = Math.floor(this.section / 2); + randomIdx = temp - randomIdx; + return idx + randomIdx; + }, + /** * * @param {*} rotation @@ -73,7 +91,9 @@ cc.Class({ this.showResult = true; } console.log('rotation=', rotation, this.rotationSpeed, idx); - + if (this.rotationSpeed <= 0) { + this.onFinish(); + } } },