Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #7

Here’s how you scale the back sprite to match the front sprite’s size, accounting for scaling.


front_sprite->setScale(4.0f);

Size front_size = front_sprite->getContentSize();
float front_x = front_sprite->getScaleX();
float front_y = front_sprite->getScaleY();
Size back_size = back_sprite->getContentSize();

back_sprite->setScale(
front_size.width*front_x/back_size.width,
front_size.height*front_y/back_size.height
);

Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #6

You can only resize the Buttons around the size of its text using the content size of the inner Label, which is called the _titleRenderer. Here’s a working lambda you can shove into your game. I suggest enabling Scale9.

    auto resize_btn = [](ui::Button* button) {
        auto lbl_size = button->getTitleRenderer()->getContentSize();

        button->setContentSize(
            Size(
                lbl_size.width * 1.1f,
                lbl_size.height * 1.1f
            )
        );
    };

Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #4

If you have the same Scene on the Director’s Scene stack, either by runWithScene or with pushScene, if you pop one off, it’ll call release on it, and effectively destroy it, making any further operations on the Scene impossible.

To resolve this, you need to call retain() on the scene, to tell cocos that somewhere else is using the scene.