Item.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { _decorator, Component, Node, Tween, tween, UIOpacity } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('Item')
  4. export class Item extends Component {
  5. @property
  6. itemType: number = 0;
  7. onLoad() {
  8. this.node.on("init", this.init, this);
  9. this.node.on("initShow", this.initShow, this);
  10. this.setBlink();
  11. }
  12. init() {
  13. this.node.active = true;
  14. setTimeout(() => {
  15. if (this.node) {
  16. this.node.active = false;
  17. }
  18. }, 0.5 * 1000);
  19. }
  20. initShow(index: number) {
  21. Tween.stopAllByTarget(this.node.getComponent(UIOpacity));
  22. this.node.getComponent(UIOpacity).opacity = 1;
  23. tween(this.node.getComponent(UIOpacity)).to(index * 0.2, { opacity: 255 }).start();
  24. }
  25. setBlink() {
  26. let random = Math.random();
  27. setTimeout(() => {
  28. let time = Math.random() * 2 + 0.5;
  29. let e1 = this.node.getChildByName("e1");
  30. let e2 = this.node.getChildByName("e2");
  31. let tw = tween(this).delay(time).call(() => {
  32. e1.active = !e1.active;
  33. e2.active = !e2.active;
  34. });
  35. tween(this).repeatForever(tw).start();
  36. }, random * 1000);
  37. }
  38. start() {
  39. }
  40. update(deltaTime: number) {
  41. }
  42. }