1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import EventName from "../EventName/EventName";
- import MyComponent from "../Template/MyComponent";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class GameTips extends MyComponent {
- @property(cc.Label)
- Hight: cc.Label = null;
- @property(cc.Label)
- Left: cc.Label = null;
- @property(cc.Label)
- Right: cc.Label = null;
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- super.onLoad()
- }
- start() {
- this.regEvent(EventName.Update_CurrentHight, this.Update_CurrentHight, this)
- this.regEvent(EventName.YaoGanMove, this.YaoGanMove, this)
- }
- Update_CurrentHight(hightNum: number) {
- this.Hight.string = `当 前 高 度 ${hightNum.toString()} M`
- }
- // YaoGanEnd(dir: cc.Vec3, power: number) {
- // // const result = parseFloat((power * 100).toFixed(2));
- // // this.History.string = `历史:${this.GetAngle(dir)}° , ${result}%`
- // }
- YaoGanMove(dir: cc.Vec3, power: number) {
- const result = parseFloat((power * 100).toFixed(0));
- this.Left.string = `角度 ${this.GetAngle(dir)}°`
- this.Right.string = `力量 ${this.FixLength(result)}%`
- }
- GetAngle(dir: cc.Vec3) {
- //根据朝向计算出夹角弧度
- var angle = dir.signAngle(cc.v2(0, 1));
- //将弧度转换为欧拉角
- // (angle / Math.PI * 180).toFixed(0);
- return this.FixLength((angle / Math.PI * 180).toFixed(0).toString())
- // let numStr = (angle / Math.PI * 180).toFixed(0).toString();
- // let spacesToAdd = 3 - numStr.length;
- // let paddedStr = "";
- // for (let i = 0; i < spacesToAdd; i++) {
- // paddedStr += " ";
- // }
- // return paddedStr + numStr;
- }
- FixLength(numStr) {
- let spacesToAdd = 4 - numStr.length;
- let paddedStr = "";
- for (let i = 0; i < spacesToAdd; i++) {
- paddedStr += " ";
- }
- return paddedStr + numStr;
- }
- onDestroy(): void {
- super.onDestroy()
- }
- }
|