andrewz
andrewz

Reputation: 5220

CCNode effective scale in world space

I'm trying to determine the "true" scale of a CCNode as it appears on the screen, ie. its content size in world space relative to its node space. This node may be embedded deep in hierarchy and have ancestor nodes with different scale and skew factors. In essence I am trying to find out the effective scaleX and scaleY factors of a node. This can be determined by transforming the bounding box of a node to the world space, and comparing their sizes. But, how to do this?

Upvotes: 2

Views: 324

Answers (1)

andrewz
andrewz

Reputation: 5220

inline CCSize effectiveSize(CCNodePtr n) {
    CCSize s = n -> getContentSize();
    CCPoint v00 = n -> convertToWorldSpace({0,0});
    CCPoint v10 = n -> convertToWorldSpace({s.width,0});
    CCPoint v01 = n -> convertToWorldSpace({0,s.height});
    return {ccpDistance(v10,v00),ccpDistance(v01,v00)};
}

CCSize size0 = myNode -> getContentSize();
CCSize size1 = effectiveSize(myNode);
float effectiveScaleX = size1.width/size0.width;
float effectiveScaleY = size1.height/size0.height;

Upvotes: 1

Related Questions