baleog
January 8, 2019, 11:24am
#1
Hello
I cannot place horizaonal layout correctly
Code from Scene init method
auto ui = cocos2d::Layer::create();
addChild(ui);
auto hbox = cocos2d::ui::HBox::create();
hbox->setPosition(cocos2d::Vec2::ZERO);
hbox->setContentSize(cocos2d::Size(101 * 10, 81 * 7));
auto map = cocos2d::TMXTiledMap::create("level.tmx");
hbox->addChild(map);
map = cocos2d::TMXTiledMap::create("rect.tmx");
hbox->addChild(map);
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.
baleog
January 8, 2019, 11:38am
#3
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?
baleog
January 8, 2019, 12:38pm
#5
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 ?
baleog
January 8, 2019, 12:53pm
#7
Using HBox is equally to use Layout with setLayoutType, isnt’t?
Layout* layout = Layout::create();
layout->setLayoutType(Layout::Type::HORIZONTAL);
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.
1 Like
HBox is only works with Widget-derived classes. (see UILayout.h comments).
2 Likes