Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sprite position is a point at the middle of the CCSprite(by default). Changing the anchor point moves the sprite such that the point moves with respect to the sprite but remains same with respect to the world space. For example, changing the anchor point of a sprite(say square) to ccp(0,0) will move the square so that its bottom left vertex will come at the position where the square's center point was initially. So while the square may seem to be "repositioned" ,its position (property) stays the same(unaffected by change in anchor point) unless specifically changed.</p> <p><strong>EDIT</strong></p> <p>If by real position of the sprite, you mean its mid point after its anchor point has been changed then it can be calculated by taking into account the two transformations that have been applied on it i.e. Translation and Rotation.</p> <p>First we take care of <strong>Translation</strong>:</p> <p>Your sprite has moved by:</p> <pre><code>CGPoint translation; translation.x = sprite.contentSize.width x (0.5 - sprite.anchorPoint.x); translation.y = sprite.contentSize.height x (0.5 - sprite.anchorPoint.y); </code></pre> <p>Now we accomodate for change in <strong>Rotation</strong></p> <p>Converting "translation" point into polar coordinates we get </p> <pre><code>#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI)) r = ccpDistance(translation,ccp(0,0)); ø = RADIANS_TO_DEGREES(atan2(translation.x,translation.y)); //i take x/y here as i want the CW angle from y axis. </code></pre> <p>If you rotated your sprite by "D" degrees:</p> <pre><code> ø = ø + D; CGPoint transPositionAfterRotation = ccp(r * cos(ø),r * sin(ø) ); CGPoint realPosition = ccp(sprite.position.x + transPositionAfterRotation.x, sprite.position.y +transPositionAfterRotation.y) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload