ToastCtrl.js 801 B

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