Confused -- ui::scale9sprite works differently 3.10 -> 3.14

Confused -- ui::scale9sprite works differently 3.10 -> 3.14
0.0 0



In my game, I successfully used setContentSize with ui:scale9sprite to scale sprites but not their children. This worked great. After upgrading to 3.14, for the life of me I can’t get any of my sprites to stretch. I’ve tried using the base Sprite class since I heard it’s merged with ui::scale9sprite. But same problem. Calling setCenterRect has no effect. Calling setStretchEnabled has no effect.

This is what I used to do:

calloutBox = ui::Scale9Sprite::createWithSpriteFrameName("callout_rect@3x.png");

Then I add a bunch of other sprites as children to the calloutBox.

Later, whenever I wanted to change the size of the calloutbox, all I had to do was:


And it would stretch callout_rect@3x.png to match the content size, and all the children would be spaced out perfectly based on their anchor points and position, but they would not be stretched themselves.

How can I accomplish now that scale9sprite has been refactored? I can’t use setScale on calloutBox or all the children will get massive etc.




I think @ricardo did some refactoring here to support c++ in Cocos Creator. Let us ask him if this is related somehow.


I guess a follow up question is this:

With the regular sprite, is there a way to add children that when you scale the parent, the children scale their positions but not sizes? For example adding a font to a sprite, and if the sprite stretches in the x or y I want the font to stay the exact same size and keep its relative position in x and y.


I’m starting to see why Sprite::setStrechEnabled has no effect when calling setContentSize. (ps is Strech without the ‘t’ a typo?)

  1. setContentSize has

if (_renderMode == RenderMode::QUAD_BATCHNODE || _renderMode == RenderMode::POLYGON)
CCLOGWARN(“Sprite::setContentSize() doesn’t strech the sprite when using BATCHNODE or POLYGON render modes”);

  1. The only way to set _renderMode to RenderMode::SLICE9 is to call setCenterRectNormalized. Unfortunately that call can only be called if already in SLICE9 mode (or quad, but quad is not the default and I’m not using it).
if (_renderMode != RenderMode::QUAD && _renderMode != RenderMode::SLICE9) {
    CCLOGWARN("Warning: Sprite::setCenterRectNormalized() only works with QUAD and SLICE9 render modes");

So I’m stuck in a cyclical dependancy that I can’t break out of.


Update: I’ve refactored my entire game to drop all references to the ui namespace. I had to hack the new Sprite class as mentioned above and then made my own button class using it.


It looks like currently Scale9 does not work for polygon sprites. Scale9 would work if not use Polygon sprites