UITips.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { _decorator,Component,Vec3,tween,Label } from "cc";
  2. import { GameMng } from "../GameMng";
  3. import { UIManager } from "./UIManager";
  4. const {ccclass, property} = _decorator;
  5. @ccclass
  6. export default class UITips extends Component {
  7. private pos:Vec3=new Vec3();
  8. private toscale:Vec3=new Vec3();
  9. private targetworldPos:Vec3=new Vec3();
  10. private isPlayAnim:boolean=false;
  11. private startScale:Vec3=new Vec3(1,1,1);
  12. private onestepScale:Vec3=new Vec3(1,1,1);
  13. private randPos:Vec3=new Vec3();
  14. playAnim(){
  15. this.isPlayAnim=true;
  16. this.node.setPosition(this.pos);
  17. this.node.setScale(this.startScale);
  18. tween(this.node)
  19. .to(0.6, { scale: new Vec3(this.onestepScale.x,this.onestepScale.y,0) }, { easing: 'smooth' })
  20. .delay(0.3)
  21. .hide()
  22. .call(() => {
  23. this.isPlayAnim = false;
  24. this.node.destroy();
  25. })
  26. .start();
  27. }
  28. static show(msg:string,worldpos?:Vec3){
  29. //return;
  30. let gnode = UIManager.AddPrefab(GameMng.Instance.uitips)
  31. let uitips = gnode.getComponent(UITips);
  32. uitips.getComponentInChildren(Label).string = msg;
  33. if(worldpos)
  34. uitips.targetworldPos = worldpos.clone();
  35. uitips.randPos.y=200;
  36. uitips.randPos.add(uitips.targetworldPos);
  37. uitips.playAnim();
  38. }
  39. update(dt:number){
  40. if(this.isPlayAnim){
  41. // this.pos=this.targetworldPos;
  42. // this.targetworldPos.lerp(this.randPos, 0.05);
  43. // this.node.setPosition(this.pos);
  44. this.targetworldPos.y+=dt*200;
  45. this.node.setPosition(this.targetworldPos)
  46. }
  47. }
  48. }