12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- cc.Class({
- extends: cc.Component,
- properties: {
- knifePrefab: cc.Prefab,
- knifeCount: {//飞刀数量
- default: 6,
- type: "Integer"
- },
- knifeIndex: {//当前飞刀索引,从0开始
- default: 0,
- type: "Integer"
- },
- knifeArr: {//飞刀Node存储队列
- default: []
- },
- isEnd: {
- default: false,
- type: "Boolean"
- }
- },
- /**
- * 初始化飞刀数量
- * @param {飞刀数量} knifeCount
- */
- init (knifeCount) {
- if(knifeCount) {
- this.knifeCount = knifeCount
- }
-
- for(let i = 0; i < this.knifeCount; i++) {
- this.knifeArr[i] = cc.instantiate(this.knifePrefab)
- this.node.addChild(this.knifeArr[i])
- this.knifeArr[i].setPositionY(-30 * (i + 1))
- }
- },
- /**
- * 减少一把飞刀
- */
- minus () {
- if(!this.isEnd) {
- let cur = this.knifeArr[this.knifeIndex]
- cur.getComponent('Lifechip').play()
-
- this.knifeIndex += 1;
- if(this.knifeIndex == this.knifeCount) {
- this.isEnd = true
- }
- }
- },
-
- /**
- * 重置飞刀队列
- */
- reset () {
- this.knifeArr = []
- },
- start () {
- },
- // update (dt) {},
- });
|