Strange Error when I port to 3.14.1 ->Sprite::setContentSize() doesn't strech the sprite when using BATCHNODE

Hi, Can anyone help with this… I have just updated my app to the latest version of cocos2dx and I get many of these?

setContentSize : Sprite::setContentSize() doesn't strech the sprite when using BATCHNODE or POLYGON render modes

Thanks

Funny thing this is a warning from what I can tell… but why? Is it possible to switch render modes???

Seems it’s something new from 14 or 14.1. By the look of it, you can’t manually change the render mode; it is automatically set.

Why? It appears they have now added multiple rendering modes for Sprite (obviously), so I guess they want to make sure you are aware when you are trying to stretch the sprite, i.e. setting its content size, when the rendering mode doesn’t allow it.

I imagine you have 2 options:

  1. Scale your sprites instead of setting their content size. This can be a little annoying, though, for reasons such as any children nodes of the sprite will scale too. Or,
  2. Don’t create a Sprite in BATCHNODE or POLYGON render mode. If you can’t get around this, then option 1 might be your only option.

So,

  • BATCHNODE is set when you call setBatchNode with a SpriteBatchNode.
  • POLYGON is set when you create/initialise with PolygonInfo, call setPolygonInfo, or call setSpriteFrame with a SpriteFrame that has PolygonInfo. (A SpriteFrame appears to only have PolygonInfo if it is created by the SpriteFrameCache using addSpriteFramesWithDictionary and the dictionary contains vertex data.)

My sprites are all coming from texture packer and I load them into the cache. Pretty sure I’m not setting any of these things explicity. SetContentSize is however being called a few times on a Layer but I’m seeing many more messages than I have instances of the layer class… seems to happen when I transition into a scene. Could it be a texture packer setting? I’m using pvr.ccz format… confused.:scream:

This looks like it might be the root of this problem https://www.codeandweb.com/texturepacker/tutorials/cocos2d-x-performance-optimization

Yup, you do seem to be correct. Just loaded a sprite sheet with that optimization and set its content size, and it gave me that warning. Guess you will have to figure out where your code is trying to alter the content size.

I’d recommend putting a breakpoint at the warning message (line 1273 of CCSprite.cpp for me) and following the stack trace to find the code that is trying to set the content size that is triggering the warning.

I struggling to understand this, the buttons images are coming from a texture packed file. The stack looks like it’s something the button renderer is doing… hmmm… can you help further???

Well my guess would be that the image you are using for a button is coming from a texture packed file with the polygon trimming optimization. If this is true, then I guess you’d need to recreate your texture packed file with a different optimization.

EDIT: I tested this and can confirm that I get the warning when creating a button using a sprite sheet with the polygon optimization, but not when using a PNG sprite sheet or PVR.CCZ without the polygon optimization. The fact it is happening when the renderer visits the button will likely be just to ensure the button’s size is up-to-date before rendering it.

1 Like

So, I’m guessing that having the optimisation turned on is improving performance and the warning is just that a warning?

According to the site you posted, it is improving performance, but the performance increase they show is based on using 500 sprites. If you only have a few buttons on screen at the same time, then the performance increase is probably quite small. But whether or not it’s worth it is up to you.

It is a warning, but it does mean something. What I’m pretty sure it means is that if you are setting the sprite’s content size and that content size differs from the sprite’s actual size, then the content size will no longer match the size of the sprite. For example, if buttons use the content size to detect touch then you could end up with buttons where tapping some parts will not be detected (if the content size is smaller than the sprite’s size) or tapping some parts outside of the button will be detected as touching the button (if the content size is larger than the sprite’s size.) Again, it’s up to you if you want to ignore this. It’s possible the content size and the actual size of the buttons will be the same and you will have no problems, but personally I’d consider it a bad idea.

1 Like

Thanks for your help. I do only have a few sprites at least in the Sprite sheet for UI controls so it’s likely to be better to turn the flag off by the sounds of it.

Also to save anyone else trying to work this out, it’s this settings that I had to change in Texture Packer to get rid of the warnings.

after setting your trim mode to “Trim” it doesn’t cut out the transparent parts, do you guys think its safe to ignore the “setContentSize : Sprite::setContentSize() doesn’t strech the sprite when using BATCHNODE or POLYGON render modes” if we are not calling setContentSize() on the button ???