简体   繁体   English

对于非矩形PNG,如何确定Cocos2d中的anchorPoint?

[英]How is anchorPoint in Cocos2d determined for non-rectangular PNGs?

I know this is a basic question, but I couldn't find a definitive answer online. 我知道这是一个基本问题,但是我无法在网上找到明确的答案。 I've read this great answer to a question on anchorPoints in general, but the user starts his answer with: 通常,我已经阅读了有关anchorPoints的一个很好的问题答案 ,但是用户从以下位置开始回答:

Let's assume your rectangular sprite image 假设您的矩形精灵图片

I understand very clearly in this case where the default anchor point (0.5f, 0.5f) will be. 在这种情况下,我将非常清楚地了解默认锚点(0.5f,0.5f)。 My question is: If you have an irregularly shaped PNG image (ie, non-rectangular), how exactly is the anchorPoint determined? 我的问题是: 如果您有一个不规则形状的PNG图像(即非矩形),如何精确确定anchorPoint?

My strong hunch is that the "width" and "height" in this case are taken to be equal to those of the smallest bounding rectangle . 我的强烈直觉是,在这种情况下,“宽度”和“高度”应等于最小边界矩形的宽度和高度。 This is illustrated below: 如下图所示:

anchorPoint边界矩形的中间

However, there are other possibilities to calculate the center point of a non-rectangular image, such as using the " center of mass " of the image: 但是,还有其他方法可以计算非矩形图像的中心点,例如使用图像的“ 质心 ”:

使用质心的anchorPoint

Can someone either confirm or refute my hunch? 有人可以确认还是驳斥我的直觉? Thanks. 谢谢。

The anchor point is always calculated based on the content size of a node. 锚点始终基于节点的内容大小来计算。 Per default a CCSprite has a content size of the image that you used as a texture, so the image size of the texture is the basis of the calculation. 默认情况下, CCSprite具有用作纹理的图像的内容大小,因此纹理的图像大小是计算的基础。

The content of the image is not relevant only the dimensions influence the content size. 图像的内容无关紧要,只有尺寸会影响内容的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM