1. 获得obj世界坐标
export function getWorldPosition(obj: cc.Node) {
return obj.convertToWorldSpaceAR(cc.Vec2.ZERO);// 获得obj世界坐标
}
2.获得obj(Center中心点)的世界坐标
export function getWorldPositionCenter(obj: cc.Node) {
let position: cc.Vec2 = getWorldPosition(obj);
let newPos: cc.Vec2 = new cc.Vec2(position.x + obj.width / 2, position.y - obj.width / 2);
return newPos;// 获得obj中心点世界坐标
}
3. 拆分字符串string,成list
export function splitString(str: string, char: string = '|'): Array<string> {
let list: Array<string> = str.split(char);
return list;
}
4. 拆分字符串string,成 color
export function getColor(str: string, char: string = ','): cc.Color {
let list: Array<string> = str.split(char);
if (list != null) {
if (list.length >= 3)
return cc.color(Number(list[0]), Number(list[1