如果Node的实际类型是Layer或者其派生类,
setPosition是不是有猫腻?
std::string menuImage = "menu.png"; auto menuItem = MenuItemImage::create(menuImage,menuImage,NULL,this); auto menu = Menu::create(menuItem,NULL); auto menuItemPoint = Point(...,...); //具体按钮位置是由menuItem的setPosition调用决定。而不是Menu的setPosition. menuItem->setPosition(menuItemPoint); //貌似设置menu的anchor没作用 //menu->setAnchorPoint(Point::ZERO); //这个setPosition ....打酱油?。可又是,去掉不显示. //但又不是按menu的anchor点显示在父Layer的ZERO位置 menu->setPosition(Point::ZERO); //添加到父Layer中 addChild(menu,1);
新建一个Layer对象,调用其 getContentSize(),返回是(0,0)
auto label = LabelTTF::create( "left_bottom", "Arial", 24); label->setPosition(Point::ZERO); label->setAnchorPoint(Point::ZERO); addChild(label);
label 却会按anchor正常显示在左下角..
----------
在一个Layer的anchor放置一个精灵,将这个Layer设置到父Layer的ZERO位置,精灵却不在ZERO位置
auto layer = Layer::create(); auto layersize = layer->getContentSize(); auto layerAnchor = layer->getAnchorPoint(); auto sprite = Sprite::create(s_pathClose); auto anchorPoint = Point(layersize.width * layerAnchor.x,layersize.height * layerAnchor.y); sprite->setPosition(anchorPoint); layer->addChild(sprite); layersize = layer->getContentSize(); //Point layPoint = Point::ZERO; layer->setPosition(Point::ZERO); addChild(layer);
这篇博文 :http://blog.csdn.net/xuguangsoft/article/details/8425623
有讲Layer的anchor是左下角,一切就都对上了,但是Layer::getAnchorPoint()返回的是(0.5,0.5)..
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ezhong的博客签名-------------------------------------
以上内容来自ezhong的博客园,作者:ezhong
ezhong的博客园: http://www.cnblogs.com/ezhong
感谢您的阅读。感谢您的分享。