Barricade.ts 903 B

12345678910111213141516171819202122232425262728293031
  1. import { _decorator, Component, Node, tween, Tween, Vec3, view } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('Barricade')
  4. export class Barricade extends Component {
  5. originPosition: Vec3 = new Vec3();
  6. start() {
  7. this.originPosition = this.node.getWorldPosition().clone();
  8. }
  9. //踢飞到屏幕外
  10. tick() {
  11. const ad = this.node.getChildByName('Ad')!;
  12. ad.active = false;
  13. const size = view.getVisibleSize();
  14. Tween.stopAllByTarget(this.node);
  15. tween(this.node)
  16. .to(0.5, { worldPosition: new Vec3(size.width, this.node.worldPosition.y + 200, 0), angle: Math.random() * 1 > 0.5 ? 360 : -360 })
  17. .call(() => {
  18. this.node.active = false;
  19. this.node.angle = 0;
  20. this.node.setWorldPosition(this.originPosition);
  21. })
  22. .start();
  23. }
  24. }