# Cocos2d sprite's parent not reflecting true scale value

I am encountering issues with determining a CCSprite's parent node's scale value.

In my game I have a class that extends CCLayer and scales itself based on game triggers. Certain child sprites of this CCLayer have mathematical calculations that become inaccurate once I scale the parent CCLayer. For instance, I have a tank sprite that needs to determine its firing point within the parent node.

Whenever I scale the layer and ask the layer for its scale values, they are accurate. However, when I poll the sprites contained within the layer for their parent's scale values, they always appear as one.

// From within the sprite
CCLOG(@"ChildSprite-> Parent's scale values are scaleX: %f, scaleY: %f",
self.parent.scaleX, self.parent.scaleY); // Outputs 1.0,1.0

// From within the layer
CCLOG(@"Layer-> ScaleX : %f, ScaleY: %f , SCALE: %f",
self.scaleX, self.scaleY,     self.scale); // Output is 0.80,0.80


Could anyone explain to me why this is the case? I don't understand why these values are different. Maybe I don't understand the inner design of Cocos2d fully. Any help is appreciated.

I believe this is related to the scene graph and parent/child relations. As the child's transformation matrices are computed against the parent, the parent is the world origin of transformation.

The child is perceiving up the scene graph tree as an individual node, they see the parent as a transform reference and if the parent is always uniformly scaled, as this is their world transform.

Try experimenting with non-uniform scale values of the parent and see how this is reflected from the child's perspective. From this you can create a scaling percentage offset that the child can use in it's own calculations(You can't extract the exact location, but you can extract the offset from the world origin of the parent).

• Turns out it was because self.parent references the spriteBatchNode the sprite is contained within – Paul Renton Jul 1 '13 at 0:07

Going to answer my own question... This is the code I am using to insert a sprite into the layer

EarthTank * earthTank = [[EarthTank alloc] initWithWorld:self->world
atLocation:spawnPointRight withID:pid];
earthTank.tankShaft = shaft;
[earthTank createInitialArsenal:tempPlayer];