cocos2dx 3.3中getParentToNodeTransform实现如下:
const Mat4& Node::getParentToNodeTransform() const
{
if ( _inverseDirty ) {
_inverse = _transform.getInversed();
_inverseDirty = false;
}
return _inverse;
}
按上面代码,一旦判断出_inverseDirty==true,就用_transform去计算_inverse,但如果此时_transform也是dirty的(存在这种可能),结果就会出错。
下面代码复现这个bug:
//----test code to show getParentToNodeTransform bug
CCNode* node=CCNode::create();
addChild(node);
node->setPosition(ccp(100,100));
//node->getNodeToParentTransform();//if you open this line, you can see different output.
Mat4 parentToNodeTransform=node->getParentToNodeTransform();
cout<<"parentToNodeTransform:"<<endl;
for(int i=0;i<16;i++){
cout<<parentToNodeTransform.m<<" ";
}cout<<endl;
时间: 2024-11-29 09:09:41