GameTips.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. History: cc.Label = null;
  16. @property(cc.Label)
  17. Now: cc.Label = null;
  18. // LIFE-CYCLE CALLBACKS:
  19. onLoad() {
  20. super.onLoad()
  21. }
  22. start() {
  23. this.regEvent(EventName.Update_CurrentHight, this.Update_CurrentHight, this)
  24. this.regEvent(EventName.YaoGanEnd, this.YaoGanEnd, this)
  25. this.regEvent(EventName.YaoGanMove, this.YaoGanMove, this)
  26. }
  27. Update_CurrentHight(hightNum: number) {
  28. this.Hight.string = hightNum.toString()
  29. }
  30. YaoGanEnd(dir: cc.Vec3, power: number) {
  31. const result = parseFloat((power * 100).toFixed(2));
  32. this.History.string = `历史:${this.GetAngle(dir)}° , ${result}%`
  33. }
  34. YaoGanMove(dir: cc.Vec3, power: number) {
  35. const result = parseFloat((power * 100).toFixed(2));
  36. this.Now.string = `${this.GetAngle(dir)}° , ${result}%`
  37. }
  38. GetAngle(dir: cc.Vec3) {
  39. //根据朝向计算出夹角弧度
  40. var angle = dir.signAngle(cc.v2(0, 1));
  41. //将弧度转换为欧拉角
  42. return (angle / Math.PI * 180).toFixed(0);
  43. }
  44. onDestroy(): void {
  45. super.onDestroy()
  46. }
  47. }