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

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

#1

Hello,

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");
calloutBox->setScale9Enabled(true);
calloutBox->setAnchorPoint(Point(0.5,0.5));
calloutBox->setPosition(Vec2(visibleSize.width*0.5,visibleSize.height*0.5));

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:

calloutBox->setContentSize(Size(visibleSize.width*_multiplier,visibleSize.width*_multiplier*_heightRatio));

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.

Thanks


#2

@ricardo?

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


#3

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.


#4

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");
    return;
}

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


#5

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.


#6

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