Life.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. knifePrefab: cc.Prefab,
  5. knifeCount: {//飞刀数量
  6. default: 6,
  7. type: "Integer"
  8. },
  9. knifeIndex: {//当前飞刀索引,从0开始
  10. default: 0,
  11. type: "Integer"
  12. },
  13. knifeArr: {//飞刀Node存储队列
  14. default: []
  15. },
  16. isEnd: {
  17. default: false,
  18. type: "Boolean"
  19. }
  20. },
  21. /**
  22. * 初始化飞刀数量
  23. * @param {飞刀数量} knifeCount
  24. */
  25. init (knifeCount) {
  26. if(knifeCount) {
  27. this.knifeCount = knifeCount
  28. }
  29. for(let i = 0; i < this.knifeCount; i++) {
  30. this.knifeArr[i] = cc.instantiate(this.knifePrefab)
  31. this.node.addChild(this.knifeArr[i])
  32. this.knifeArr[i].setPositionY(-30 * (i + 1))
  33. }
  34. },
  35. /**
  36. * 减少一把飞刀
  37. */
  38. minus () {
  39. if(!this.isEnd) {
  40. let cur = this.knifeArr[this.knifeIndex]
  41. cur.getComponent('Lifechip').play()
  42. this.knifeIndex += 1;
  43. if(this.knifeIndex == this.knifeCount) {
  44. this.isEnd = true
  45. }
  46. }
  47. },
  48. /**
  49. * 重置飞刀队列
  50. */
  51. reset () {
  52. this.knifeArr = []
  53. },
  54. start () {
  55. },
  56. // update (dt) {},
  57. });