Cocos2d-x convertToNodeSpace anchorpoint

时间:2015-10-20 18:10:52

标签: cocos2d-iphone cocos2d-x cocos2d-x-3.0

您好我遇到了convertToNodeSpace方法的问题。 当我将精灵的锚点设置为0.5,0.5时,convertToNodeSpace无法正常工作。

示例锚点0,0和1,1可以工作

Sprite *sprite1 = Sprite::create("CloseNormal.png");
sprite1->setPosition(Vec2(20,40));
sprite1->setAnchorPoint(Vec2(0,0));
this->addChild(sprite1);

Sprite *sprite2 = Sprite::create("CloseNormal.png");
sprite2->setPosition(Vec2(5,-20));
sprite2->setAnchorPoint(Vec2(1,1));
this->addChild(sprite2);

Vec2 point1 = sprite1->convertToNodeSpace(sprite2->getPosition());

输出为position =( - 15.000000,-60.000000),如预期 但是当我将两个锚点都改为0.5时,我得到以下输出

Sprite *sprite1 = Sprite::create("CloseNormal.png");
sprite1->setPosition(Vec2(20,40));
sprite1->setAnchorPoint(Vec2(0.5,0.5));
this->addChild(sprite1);

Sprite *sprite2 = Sprite::create("CloseNormal.png");
sprite2->setPosition(Vec2(5,-20));
sprite2->setAnchorPoint(Vec2(0.5,0.5));
this->addChild(sprite2);

输出位置=( - 5.625001,-50.625000)

将精灵添加到节点时,0.5 0.5锚点用于设置位置。也许我错过了什么?这个输出对我来说似乎很奇怪

0 个答案:

没有答案