2dtoolkit获取sprite像素大小的方法

时间:2023-11-30 15:42:14

获取sprite像素的方法

Vector2 GetPixelSize(tk2dSpriteDefinition def){
float w = def.untrimmedBoundsData[].x;
float h = def.untrimmedBoundsData[].y; // Calculate dimensions in pixel units
float pixelWidth = w / def.texelSize.x;
float pixelHeight = h / def.texelSize.y; Vector2 sizeVec = new Vector2(pixelWidth, pixelHeight);
return sizeVec;
}

其中的def参数只要转入spirte实例的CurrentSprite属性就可以了,slicedSprite同理