Farmland.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. stateArray: {
  5. default: [],
  6. type: cc.SpriteFrame,
  7. serializable: true,
  8. },
  9. changeSprite: {
  10. default: null,
  11. type: cc.Sprite,
  12. serializable: true,
  13. },
  14. //工作状态
  15. workingStatus: {
  16. default: null,
  17. type: cc.Node,
  18. serializable: true,
  19. },
  20. },
  21. // start(){
  22. // this.onChangeSpriteFunction(2);
  23. // },
  24. onChangeSpriteFunction(consume) {
  25. if (consume <= 0 || consume >= 50) {
  26. this.workingStatus.active = false;
  27. } else if (!this.workingStatus.active) {
  28. this.workingStatus.active = true
  29. }
  30. let index = 50 - consume;
  31. // let index = consume%3;
  32. // cc.log(Math.floor(this._Strength % 3));
  33. if (index >= 15 && index <= 25)
  34. this.changeSprite.spriteFrame = this.stateArray[1];
  35. else if (index > 25)
  36. this.changeSprite.spriteFrame = this.stateArray[2];
  37. },
  38. onResetSprite() {
  39. this.changeSprite.spriteFrame = this.stateArray[0];
  40. }
  41. });