1
0

CityItem.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. cityPic: cc.Sprite,
  5. incomeSpeedLabel: cc.Label,
  6. indexLabel: cc.Label,
  7. stateSprite: cc.Sprite,
  8. incomeLayout: cc.Node,
  9. },
  10. // onLoad () {},
  11. init(info, incomeSpeed) {
  12. this.info = info;
  13. this.indexLabel.string = info.id;
  14. this.indexLabel.node.active = true;
  15. if (info.selected) {
  16. this.statePath = 'selected';
  17. this.picPath = info.picId + '_';
  18. } else if (info.unlock) {
  19. this.statePath = 'unlocked';
  20. this.picPath = info.picId + '_';
  21. } else {
  22. this.statePath = 'lock';
  23. this.picPath = info.picId;
  24. this.indexLabel.node.active = false;
  25. }
  26. console.log('picPath: ', this.picPath);
  27. cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
  28. this.cityPic.spriteFrame = spriteFrame;
  29. });
  30. cc.loader.loadRes('./map/' + this.statePath, cc.SpriteFrame, (err, spriteFrame) => {
  31. this.stateSprite.spriteFrame = spriteFrame;
  32. });
  33. if (incomeSpeed > 0) {
  34. this.incomeLayout.active = true;
  35. this.incomeSpeedLabel.string = `${incomeSpeed}/天`;
  36. } else {
  37. this.incomeLayout.active = false;
  38. }
  39. },
  40. start() {
  41. },
  42. fakeLock() {
  43. cc.loader.loadRes('./map/' + this.info.picId, cc.SpriteFrame, (err, spriteFrame) => {
  44. this.cityPic.spriteFrame = spriteFrame;
  45. });
  46. cc.loader.loadRes('./map/' + 'lock', cc.SpriteFrame, (err, spriteFrame) => {
  47. this.stateSprite.spriteFrame = spriteFrame;
  48. });
  49. },
  50. fakeUnLock() {
  51. cc.loader.loadRes('./map/' + this.info.unlockPicId, cc.SpriteFrame, (err, spriteFrame) => {
  52. this.cityPic.spriteFrame = spriteFrame;
  53. });
  54. cc.loader.loadRes('./map/' + 'unlock', cc.SpriteFrame, (err, spriteFrame) => {
  55. this.stateSprite.spriteFrame = spriteFrame;
  56. });
  57. },
  58. showFinishAnimation(cb) {
  59. this.cityPic.node.setScale(0);
  60. let end = cc.callFunc(() => {
  61. cb && cb();
  62. }, this);
  63. let scale = cc.sequence(cc.scaleTo(0.3, 1, 1).easing(cc.easeBackOut()), end);
  64. this.cityPic.node.runAction(scale);
  65. },
  66. // update (dt) {},
  67. });