Iām certain there isn’t a error within the location of the plist file and png picture, why is that this error nonetheless displaying?
the code as follows:
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("/protagonist_move/a.plist");
auto pSprite2 = Sprite::create();
pSprite2->setPosition(500, 600);
this->addChild(pSprite2,2);
Vector<SpriteFrame*>checklist;
checklist.reserve(2);
checklist.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("/protagonist_move/10001.png"));
checklist.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("/protagonist_move/10002.png"));
auto pAnimation = Animation::createWithSpriteFrames(checklist, 0.2f, 1000);
auto pAnimate = Animate::create(pAnimation);
pSprite2->runAction(pAnimate);
the errors as follows:
please take away ā/ā from āā/protagonist_move/a.plist” => “āprotagonist_move/a.plistā
The issue nonetheless exists after modification
I uploaded the demo file, please check out what’s the downside.
demo.zip (1.2 MB)
The proper sprite body identify is ā10020.pngā and ā10021.pngā, you possibly can examine it in aaaa.plist, additionally you donāt want 10020.png and 10021.png, the aaaa.plist will add aaaa.png.
If 10020.png and 10021.png should not wanted, how ought to the code be written?
The a.plist ought to containing the sprite body identify, then you need to use the identify to get the body from cache.
https://docs.cocos.com/cocos2d-x/handbook/en/sprites/spriteframe_cache.html
The next is a press release that fetches frames from the cache:
SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10020.png")
This sentence is contained within the following code:
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("protagonist_move/aaaa.plist");
auto pSprite2 = Sprite::create();
pSprite2->setPosition(500, 600);
this->addChild(pSprite2, 2);
Vector<SpriteFrame*>checklist;
checklist.reserve(2);
checklist.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10020.png"));
checklist.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10021.png"));
auto pAnimation = Animation::createWithSpriteFrames(checklist, 0.2f, 1000);
auto pAnimate = Animate::create(pAnimation);
pSprite2->runAction(pAnimate);
However the error within the title seems after working. doesnāt clear up the issue.
In your demo.zip, the aaaa.plist incorporates 2 sprite body, which named 10020.png and 10021.png, while you add aaaa.plist to SpriteFrameCache, get the SpriteFrame by identify 10020.png and 10021.png.
Could also be you misunderstand the utilization of sprite sheet and sprite body cache.
You donāt want /demo/Sources/protagonist_move/10020.png and 10021.png within the mission when including sprite sheet to SpriteFrameCache, simply aaaa.plist and aaaa.png is sufficient.
All of the wanted data is saved in aaaa.plist, you possibly can examine it by textual content editor.
Please look additionally on the examples on cpp_test.
Plz learn additionally the doc. The API und possibly additionally some c++ Tutorials too.
I belive you be a c++ newbie.
1 Like
I hope you discover this recommendation to be useful. Please contact us in case you require any extra help.