ToastCtrl.js 865 B

12345678910111213141516171819202122232425262728293031323334353637
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. label: cc.Label,
  5. },
  6. onLoad() {
  7. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  8. // this.close();
  9. });
  10. },
  11. show(message) {
  12. this.label.string = message;
  13. this.node.active = true;
  14. this.node.y = - this.node.height;
  15. let anim = cc.spawn(cc.moveBy(0.3, 0, this.node.height), cc.fadeOut(0.3));
  16. this.node.runAction(anim);
  17. this.timer = setInterval(() => {
  18. this.close();
  19. }, 1000);
  20. },
  21. // update (dt) {},
  22. close() {
  23. clearInterval(this.timer);
  24. let anim = cc.spawn(cc.moveBy(0.3, 0, this.node.height), cc.fadeOut(0.3));
  25. let end = cc.callFunc(() => {
  26. this.node.active = false;
  27. });
  28. this.node.runAction(cc.sequence(anim, end));
  29. },
  30. });