cocos2dx 3.3 getParentToNodeTransform bug

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;

参考:http://www.cocoachina.com/bbs/read.php?tid-287885.html

posted on 2015-03-11 16:19  wantnon  阅读(940)  评论(0编辑  收藏  举报

导航