I’m attempting to upgrade from 3.13.1 to 3.17.1 and found that calling setContentSize() on a sprite scales the sprite. This does not happen on 3.13.1. Is this an intended change as I thought setScale was clearly separated from it.
Also notice it only scales the base sprite, child sprites are unaffected.
I’ll also add that this is definitly not my code issue as I was able to reproduce this from cocos2d-x test projects. Here is a screenshot from the game-controller-test project as I was playing around with it (THANK YOU FOR ADDING CONTROLLER SUPPORT)
You may have missed the message before the screenshot, you can reproduce this simply by adding a sprite to any scene and call setContentSize(). I provided example in that post, and if you setContentSize to zero the sprite disappears. You can literally just create a new project and paste the code in to your HelloWorld init scene. Here’s the code again:
auto sprite = Sprite::create("omg.png");
sprite->setContentSize(Size::ZERO);
sprite->setPosition(visibleSize/2); //centers the sprite
addChild(sprite);
I added the line that centers the sprite so you can more clearly see it
to achieve zero position under unique circumstances
when adding child elements to a sprite I need to adjust overall content size to matched the resulting combined sprite
this breaks both of these. You can argue the first point is more hack-ish but the second point is a legitimate use. I use it quite often, and it ends up stretching the base image.
I just checked CCSprite.h on 3.13.1 setStretchEnabled does not exist so this seem like it’s an intended change. At least it should be off by default as it is incompatible with earlier versions of cocos.
This change has been in there since Cocos2d-x v3.14, released on Jan 3, 2017, so it’s not something recent. It may not be a good idea for stretch to be changed back to “false”, because it seems like this is the first reported issue with this behavior, and there have been many releases after it was introduced, so changing it back may affect all products released since v3.14.
The correct behavior should be dictated by the typical (ie, most common) use case for setContentSize(). The two options here are:
(1) Sprite scales to the content size
(2) Sprite canvas size changes without scaling texture
Perhaps there should have been a request for feedback regarding this change before it was introduced in v3.14, but given that it’s been in there for the past 2+ years, and many releases, along with the fact that there haven’t been any other posts regarding this implementation, it may be best to leave it as is.
While you guys are here anyone care to take a look at another bug I submitted on github regarding setWindowed and getVisibleSize? When I submit bugs on github I usually don’t get any responses. I can start another thread if there needs a discussion. Thanks