cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.18k stars 7.05k forks source link

Using contentSize instead of winSize for Menu #17069

Closed fyt000 closed 7 years ago

fyt000 commented 7 years ago

As in title, Menu always set everything with respect to windows size. For example, In Menu::alignItemsInColumnsWithArray we have Size winSize = Director::getInstance()->getWinSize(); The position of each MenuItem will be set relative to the winSize. This makes it very difficult to align items in a given area, it always expands to the whole screen. I suggest changing it to the following Size winSize = getContentSize(); So that we can do something like menu->setContentSize(Size(vsize,hsize)); to easily limit the span of the menu. As by default we will fall back and use the windows size.

Bilalmirza commented 7 years ago

I think it would be better if its menu->setPosition(Point::Zero);

I have to call this every time i create a menu.

minggo commented 7 years ago

@three0s it sounds reasonable. @ricardoquesada what's your opinion?

ricardoquesada commented 7 years ago

@minggo makes sense. PR here: https://github.com/cocos2d/cocos2d-x/pull/17090

minggo commented 7 years ago

@ricardoquesada thanks. The PR breaks compatibility, i think it is better to keep compatible by default, and add a new method to use content size.

fyt000 commented 7 years ago

or just add a default parameter to use the windows size

ricardoquesada commented 7 years ago

@minggo it might break compatibility if the user changed the menu's contentSize manually. But by default, the menu's contentSize() is the Director's contentSize. See this line: https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.13.1/cocos/2d/CCMenu.cpp#L142

Bilalmirza commented 7 years ago

hey, I was wondering why use contentSize? All nodes are created with Point::Zero position why change it here? I understand its usability in multi-resolution but we lose the consistency in code due to this.

ricardoquesada commented 7 years ago

@Bilalmirza sorry, I didn't understand the question. we are not changing menu's contentSize. we are just using it instead of using Director's winSize. And by default, menu's contentSize is Director's winSize.

Bilalmirza commented 7 years ago

@ricardoquesada oh okay, thanks