import {
_decorator, Component, Node, Vec2, Vec3, Quat, Camera, UITransform, view, log, Constructor, BoxCollider, geometry, SphereCollider, Mat3, director } from 'cc';
import {
ColliderEx } from './ColliderEx';
const {
ccclass, property } = _decorator;
export default class Util {
static physicsMoveFactor: number = 70;
/**
* 返回 min ~ max 的随机数
* @param min 最小值(包含)
* @param max 最大值(包含)
*/
static Random(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
/**
* 求两点之间的距离
* @param point1 点1
* @param point2 点2
*/
static Distance(point1: Vec2, point2: Vec2): number {
return Math.sqrt(Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2));
}
//直线与坐标轴的夹角 (斜率转角度) 返回的是一个弧度值
static Angle(point1: Vec2, point2: Vec2): number {
let x = point2.x - point1.x;
let y = point2.y - point1.y;
return Math.atan2(y, x);
}
/**
* 将秒数格式化为00:00
* @param second 秒数
*/
static GetTimeFormat(second: number) {
let mStr = "";
let sStr = "";
let m = Math.floor(second / 60);
let s = second % 60;
if (m < 10)
mStr = "0" + m;
else
mStr = m.toString();
if (s < 10)
sStr = "0" + s;
else
sStr = s.toString();
return "mm:ss".replace("mm", mStr).replace("ss", sStr);
}
/**
* 获取当前时间戳。得到距 1970 年 1 月 1 日之间的毫秒数,13位
*/
static GetNowTimestamp(): number {
return new Date().getTime();
}
/**
* 获取当前时间戳。单位秒
*/
static GetTime(): number{
let time = Date.now() / 1000;
let second = Math.floor(time);
return second;
}
/**
* 时间戳转换日期
* @param timestamp 时间戳,13位
*/
static TimestampToDate(timestamp): string {
let time = parseInt(timestamp);
if (timestamp.length < 13) //要转化为毫秒
time = time * 1000;
return new Date(time).toLocaleString();
}
//深拷贝
static DeepClone(obj): any {
let
CocosCreator 工具类(持续更新)
于 2022-04-29 17:09:41 首次发布
本文档持续更新,详细介绍了使用CocosCreator进行游戏开发过程中的一些实用工具类,涵盖JavaScript编程,帮助开发者提高效率,简化开发流程。
摘要由CSDN通过智能技术生成