GameTips.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName from "../EventName/EventName";
  8. import MyComponent from "../Template/MyComponent";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class GameTips extends MyComponent {
  12. @property(cc.Label)
  13. Hight: cc.Label = null;
  14. @property(cc.Label)
  15. Now: cc.Label = null;
  16. // LIFE-CYCLE CALLBACKS:
  17. onLoad() {
  18. super.onLoad()
  19. }
  20. start() {
  21. this.regEvent(EventName.Update_CurrentHight, this.Update_CurrentHight, this)
  22. // this.regEvent(EventName.YaoGanEnd, this.YaoGanEnd, this)
  23. this.regEvent(EventName.YaoGanMove, this.YaoGanMove, this)
  24. }
  25. Update_CurrentHight(hightNum: number) {
  26. this.Hight.string = `当前高度 ${hightNum.toString()} M`
  27. }
  28. // YaoGanEnd(dir: cc.Vec3, power: number) {
  29. // // const result = parseFloat((power * 100).toFixed(2));
  30. // // this.History.string = `历史:${this.GetAngle(dir)}° , ${result}%`
  31. // }
  32. YaoGanMove(dir: cc.Vec3, power: number) {
  33. const result = parseFloat((power * 100).toFixed(2));
  34. this.Now.string = `${this.GetAngle(dir)}° , ${result}%`
  35. }
  36. GetAngle(dir: cc.Vec3) {
  37. //根据朝向计算出夹角弧度
  38. var angle = dir.signAngle(cc.v2(0, 1));
  39. //将弧度转换为欧拉角
  40. return (angle / Math.PI * 180).toFixed(0);
  41. }
  42. onDestroy(): void {
  43. super.onDestroy()
  44. }
  45. }