0

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:

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. My question is: If you have an irregularly shaped PNG image (i.e., non-rectangular), how exactly is the anchorPoint determined?

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 middle of bounding rectangle

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 using center of mass

Can someone either confirm or refute my hunch? Thanks.

Community
  • 1
  • 1
Alex P. Miller
  • 2,128
  • 1
  • 23
  • 20
  • 2
    There is no such thing as non-rectangular PNG, it is just a rectangular PNG with some transparency. So the anchor point of the sprite will be always just in the center of that image (unless you change it). – Insomniac Jul 21 '14 at 15:59

1 Answers1

0

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.

The content of the image is not relevant only the dimensions influence the content size.

Ben-G
  • 4,996
  • 27
  • 33