about cocos2d::CCSpriteBatchNode

about cocos2d::CCSpriteBatchNode
0.0 0


reference from v0.92.

if a sprite is attached to a CCSpriteBatchNode, in CCSprite’s method function CCSprite::updateTransform(void), there is a recursive-like process that update transform matrix to world space(or root batch node).

It’s something weird that it assumes that any ancient node (include sprite itself) of sprite must be type of CCSprite. There are 2 lines in the code:
prevHonor = p)
**my question is:Is it neccessary to force every ancient to be CCSprite? ’Cause sometimes sprite’s parent or grandparent is just CCNode. this forced-type-conversion may not be safe.*

PS: about CCSprite::getTransformValue(), it is method of CCSprite, however none of CCSprite’s member has been used in this function. Members used in this function are totally declared in cocos2d::CCNode. Is there any reason that can not keep this function in cocos2d::CCNode ?

  1. I agree, the forced conversion is not safe enough. The reason why is that wophone, our sponsor in the previous year, their platform didn’t support RTTI. Otherwise we would use dynamic_cast instead. The comment there described this situation.
  2. Since cocos2d 1.0, at new feature “skew” is added into sprites. I review the code now, we cannot move CCSprite::getTransformValues to CCNode because of m_fSkewX & m_fSkewY.


Thank you for your reply.:slight_smile:

However, is there any way to deal with a node tree that contains both CCSprite and CCNode, while I just want to batch CCSprite nodes?

Since some practical reasons, CCNode here is nessary. then at the batch drawing step, they are needed to call member getTransformValues() and getHornorParentTransform() which both belong to CCSprite.