完善转盘

This commit is contained in:
leo
2018-11-18 20:13:59 +08:00
parent 0a6dab364a
commit 26f9a9ccb4
2 changed files with 27 additions and 7 deletions

View File

@@ -1,2 +1,2 @@
# 转盘demo
一个简单实现的转盘demo
# hello-world
Hello world new project template.

View File

@@ -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();
}
}
},