Cocos2d iphone 为什么Cocos2d不把精灵放在我想的地方';应该是吗?

Cocos2d iphone 为什么Cocos2d不把精灵放在我想的地方';应该是吗?,cocos2d-iphone,Cocos2d Iphone,50%的时候我觉得我得到了我所期望的,而另外50%的时候,我发现自己在说“!?!?cocos2d为什么要把这个放在这里?!” 例如: parent: CCNode, anchorpoint (0.5, 0.5), position (screenWidth / 2, screenHeight / 2) child: CCSprite, anchorpoint (0.5, 0.5), position (0,0), textureRect CGRectZero, contentSize man

50%的时候我觉得我得到了我所期望的,而另外50%的时候,我发现自己在说“!?!?cocos2d为什么要把这个放在这里?!”

例如:

parent: CCNode, anchorpoint (0.5, 0.5), position (screenWidth / 2, screenHeight / 2)
  child: CCSprite, anchorpoint (0.5, 0.5), position (0,0), textureRect CGRectZero, contentSize manually set to scale of child of child
    child of child: CCSprite, anchorpoint (0.5, 0.5), position (0,0), same texture as "child", has a textureRect of something like (0,0,25,1), rotation of 90.  Its scaleY is set to 384.
我希望孩子的孩子在哪里?当然在屏幕中间。锚点在中间,

它实际上出现在哪里?在屏幕的左侧。为什么?不知道。毫无意义。

天哪

因此,它与精灵何时添加到父对象有关

如果您这样做:

CCSprite *sprite = [[CCSprite alloc] initWithFile:@"test.png" rect:CGRect(0,0,1,1)];
sprite.anchorPoint = ccp(0.5, 0.5);
sprite.scaleX = 384;
[node addChild:sprite];
那么定位就完全错了。但如果你这样做了:

CCSprite *sprite = [[CCSprite alloc] initWithFile:@"test.png" rect:CGRect(0,0,1,1)];
[node addChild:sprite];
sprite.anchorPoint = ccp(0.5, 0.5);
sprite.scaleX = 384;

然后它被正确地定位。。。完全是假的。难以置信,我在这上面浪费了这么多时间。希望这能帮助将来对这些废话大喊大叫的人。

是的。。。方舟。。。这是在3.x中引入的,允许SpriteBuilders
程序员
将Sprite定位为父对象边界框的百分比(在cocos2d中的hood
CCPositionTypeNormalized
下)。我自己不使用它,它能做的最好的事情就是在所有设备上创建笨拙的布局,只有一个设备除外。02