Cannot layout a HBox

Cannot layout a HBox



I cannot place horizaonal layout correctly
Code from Scene init method

         auto ui = cocos2d::Layer::create();
 	auto hbox = cocos2d::ui::HBox::create();
 	hbox->setContentSize(cocos2d::Size(101 * 10, 81 * 7));
 	auto map = cocos2d::TMXTiledMap::create("level.tmx");
 	map = cocos2d::TMXTiledMap::create("rect.tmx");

But it shows like this

Rect.tmx placed upon a level.tmx. But I expected it on the right side of level (empty red rectangle on image)


You have told it 0,0 which is the lower left corner.


Thank you for reply. I thought I set lower left position to hbox only. I supposed that hbox children placed in it in horizontal row. Or I should set position of each hbox child manually?


Sorry, you want the box on the left with the red border moved to the right box with the red border?


I want to place rect.tmx in a horizontal row, right of level.tmx (without manually setPosition of each child). Like this

I supposed that hbox is right container for this


ok, I see why you are using HBox now. To layout the in a horizontal line. I don’t use it.

You know the size and position of level so you can just place rect at levels width,0?


Using HBox is equally to use Layout with setLayoutType, isnt’t?

        Layout* layout = Layout::create();

Yes, I know the size and position of level. But isnt’t HBox used for automatic placing?


I’m not sure how often other developers use it. I never use it or layouts for that matter. I just always write my own calculations.

That being said, I can test HBox and see what is happening.


HBox is only works with Widget-derived classes. (see UILayout.h comments).


That explains it.