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.24k stars 7.06k forks source link

Render error when call CCSprite::initWithSpriteFrameName 2nd time #18609

Open peerobo opened 6 years ago

peerobo commented 6 years ago

Steps to Reproduce:

The following code call to CCSprite::initWithSpriteFrameName two times, cause an error in rendering.

ui::Button *bt = ui::Button::create(); bt->loadTextureNormal("SpriteFrameA", ui::Widget::TextureResType::PLIST); bt->loadTextureNormal("SpriteFrameB", ui::Widget::TextureResType::PLIST);

screenshot_2018-01-04-18-24-14

Should look like this:

screenshot_2018-01-04-18-32-24

Achieve by modify UIButton.cpp:

void Button::loadTextureNormal(const std::string& normal,TextureResType texType) { ... case TextureResType::PLIST: // _buttonNormalRenderer->initWithSpriteFrameName(normal); frm = SpriteFrameCache::getInstance()->getSpriteFrameByName(normal); _buttonNormalRenderer->setSpriteFrame(frm); break; ... }

drelaptop commented 6 years ago

Could you submit a PR for it? to add a test case like your image shows into cpp-tests project -> 45:Node: Sprite would be better.

peerobo commented 6 years ago

@drelaptop please check out the PR. Thanks!