21 lines
655 B
TypeScript
Raw Normal View History

2022-11-27 23:23:47 +08:00
import { Layers, SpriteFrame, Node, UITransform } from "cc"
const INDEX_REG = /\((\d+)\)/
const getNumberWithinString = (str: string) => parseInt(str.match(INDEX_REG)?.[1] || '0')
export const sortSpriteFrame = (spriteFrame: Array<SpriteFrame>) =>
spriteFrame.sort((a, b) => getNumberWithinString(a.name) - getNumberWithinString(b.name))
const getUIMaskNumber = () => 1 << Layers.nameToLayer('UI_2D')
export const createUINode = (name: string = '') => {
const node = new Node(name)
node.layer = getUIMaskNumber()
const transform = node.addComponent(UITransform)
return node
}
export const rad2Angle = (rad: number) => rad / Math.PI * 180