cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.14k stars 7.05k forks source link

UIButton scale9Enabled does not work with SpriteFrameCache #19901

Open phicore opened 5 years ago

phicore commented 5 years ago

Creating a UIButtons with individual sprites and activating Scale9 works as expected, But as soon I replace the individual sprites (png images) with images from the SpriteFrameCache (by setting the ResourceType to PLIST) the buttons size is no more stretched according to the given size. The sprites are shown as if Scale9Enabled was false.

I used SpriteFrameCache in the first place to lower the draw calls as I create a lot of buttons with the same images. But in addition to the issue described above, using SpriteFrameCache does not change the drawcall count.

Result is OK with individual prites: image

code:

Button* button = Button::create("TextButton\\text_button_bkgd.png", "TextButton\\text_button_bkgd_sel.png");

  button->setScale9Enabled(true);
  button->setPosition(Vec2((float)X, (float)Y));
  button->setContentSize(Size(W, H));

  button->setZoomScale(0.0f);
  button->setPressedActionEnabled(true);
  button->setOpacity(255);

Result is not right with Spriteframe cache (using Widget::TextureResType::PLIST): image

Button* button = Button::create("./text_button_bkgd", "./text_button_bkgd_sel",
                                "./text_button_bkgd_dim", Widget::TextureResType::PLIST);

  button->setScale9Enabled(true);
  button->setPosition(Vec2((float)X, (float)Y));
  button->setContentSize(Size(W, H));

  button->setZoomScale(0.0f);
  button->setPressedActionEnabled(true);
  button->setOpacity(255);
phicore commented 5 years ago

I suppose I can live with loading images instead of using an atlas. But what bothers me more is the number of draw call that is easily above 50 while I create a lot of buttons (in a listview)

phicore commented 5 years ago

Not interesting the core developpers it seems...

phicore commented 5 years ago

Could it be possible to have an answer to this issue or at least a comment

vbrun commented 4 years ago

Same problem for me but if I export the spritesheets without polygon outlines it works for me