Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix the Anchor Point issue and prepend the methods calls with this->. #16466
We are setting the anchor point to the center of the Menu so the call of setIgnoreAnchorPointForPosition must be with "true" argument. // Also prepend all the methods calls with this to keep the consistency between the calls.
@minggo I think that with "my" fix the correct is achieved.
// In a MyScene::init for example auto pMenu = cc::Menu::create(); this->addChild(pMenu);
The menu will be placed like that:
So to remedy this we must do:
// In a MyScene::init for example auto pMenu = cc::Menu::create(); pMenu->setIgnoreAnchorPointForPosition(false); this->addChild(pMenu);
Now the Menu is placed exactly on on the scene.
I think that the original behaviour is very odd,
Another point that reinforces this (or I really don't
First I change the base class of coco2d::Menu from cocos2d::Layer to cocos2d::LayerColor.
I doubt that any one is using this straight, without setting the Menu's properties before.
The code that I used is:
auto pLayer = cc::LayerColor::create(cc::Color4B::RED, this->getContentSize().width, this->getContentSize().height); this->addChild(pLayer); auto pMenu = cc::Menu::create(); this->addChild(pMenu);
The cocos2d::Layer is the red one and cocos2d::Menu is the blue one.
PS: We can have some trouble if the guy that is using the cocos2d::Menu is changing it's position to offset the wrong Menu placement, but again I think that is very unliked since the change the setIgnoreAnchorPointForPosition to false is more obvious.
What do you think?
@N2OMatt this will break existing code. Notice that it's actually redundant for Menu to set ignore and anchor as it's already set the same in Layer.
For now you can just create a utility function to an inline static method CreateMenu() that also sets ignore to false.
@stevetranby I understand, actually I'd already create a subclass for cocos2d::Menu that does this job, since I don't "feel comfortable" to mess the cocos2dx code in my games. You know, this way I can "just" swap the cocos folder to update the engine (mostly).
But regarding the issue we have a problem in my opnion.
What we can do to improve the engine? I mean, "fix the comment" and make the placement of cocos2d::Menu like it is today? Or we put this in the v4 release (I think that is ok, to break this kind
yes, I confirm that it breaks backwards compatibility.
I wouldn't break backwards compatibility in v4 for this change. It provides tiny benefit for the user, and fix it might take time: "hey all my menus are broken in v4!... how can I fix them".
what superfluous code would you like to remove?
Sorry guys, I was in a vacation last week or so, I didn't check my mail!
"@N2OMatt this will break existing code. Notice that it's actually redundant for Menu to set ignore and anchor as it's already set the same in Layer."
Thanks everyone for all the attention!