WorkerTips.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start() {
  32. this._init();
  33. },
  34. _init: function () {
  35. //0 未播放 1正播放
  36. this.state = 0;
  37. this.TipName = '';
  38. this._x = 50;
  39. this._y = 100;
  40. },
  41. _addInfo: function (callback) {
  42. cc.loader.loadRes("prefab/Info", function (err, texture) {
  43. this.info = cc.instantiate(texture);
  44. if (this.node.getChildByName(this.info.name) != null) {
  45. this.node.getChildByName(this.info.name).destroy();
  46. }
  47. this.node.addChild(this.info);
  48. this.info.x = this._x;
  49. this.info.y = this._y;
  50. this.info.active = false;
  51. if (callback != null) {
  52. callback();
  53. }
  54. }.bind(this));
  55. },
  56. //开始播放的方法
  57. playNoHouseInfoAnim: function (string) {
  58. if (this.state == 0) {
  59. this.state = 1;
  60. this._addInfo(function () {
  61. this.info.active = true;
  62. this.info.x = this._x;
  63. this.info.y = this._y;
  64. //显示信息
  65. if (string) {
  66. this.info.getChildByName('infoLabel').getComponent(cc.Label).string = string;
  67. this.TipName = string;
  68. }
  69. else {
  70. this.info.getChildByName('infoLabel').getComponent(cc.Label).string = this.TipName;
  71. }
  72. var jump = cc.jumpBy(2, 0, 0, 20, 3);
  73. var finished = cc.callFunc(function () {
  74. this.callbackstopNoHouseInfo = function () {
  75. this._reStopNoHouseInfo();
  76. }
  77. this.scheduleOnce(this.callbackstopNoHouseInfo, 1);
  78. }.bind(this));
  79. var sequence = cc.sequence(jump, finished);
  80. this.info.runAction(sequence);
  81. }.bind(this));
  82. }
  83. },
  84. //内部调用的方法
  85. _reStopNoHouseInfo: function () {
  86. this.info.active = false;
  87. this.info.stopAllActions();
  88. this.callbackrestop = function () {
  89. this.state = 0;
  90. this.playNoHouseInfoAnim();
  91. }.bind(this);
  92. this.scheduleOnce(this.callbackrestop, 1);
  93. },
  94. //停止播放的方法
  95. stopNoHouseInfoAnim: function () {
  96. this.state = 0;
  97. if (this.info != null) {
  98. this.info.active = false;
  99. this.info.stopAllActions();
  100. this.unscheduleAllCallbacks();
  101. // cc.log('this.info.name',this.info.name);
  102. if (this.info.name!=''&&this.node.getChildByName(this.info.name) != null) {
  103. this.node.getChildByName(this.info.name).destroy();
  104. }
  105. }
  106. },
  107. // update (dt) {},
  108. getNode: function (name, parent) {
  109. if (parent == null) {
  110. return this.node.getChildByName(name);
  111. } else {
  112. return parent.getChildByName(name);
  113. }
  114. },
  115. loadImg: function (container, url, w, h) {
  116. cc.loader.load(url, function (err, texture) {
  117. var sprite = new cc.SpriteFrame(texture);
  118. container.getComponent(cc.Sprite).spriteFrame = sprite;
  119. if (w != null) {
  120. container.width = w;
  121. }
  122. if (h != null) {
  123. container.height = h;
  124. }
  125. });
  126. },
  127. });