
[ad_1]
I’m certain there is no such thing as a error within the location of the plist file and png picture, why is that this error nonetheless exhibiting?
the code as follows:
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("/protagonist_move/a.plist");
auto pSprite2 = Sprite::create();
pSprite2->setPosition(500, 600);
this->addChild(pSprite2,2);
Vector<SpriteBody*>record;
record.reserve(2);
record.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("/protagonist_move/10001.png"));
record.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("/protagonist_move/10002.png"));
auto pAnimation = Animation::createWithSpriteFrames(record, 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 downside nonetheless exists after modification
I uploaded the demo file, please check out what’s the downside.
demo.zip (1.2 MB)
The right sprite body title is “10020.png” and “10021.png”, you may verify 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 are usually not wanted, how ought to the code be written?
The a.plist ought to containing the sprite body title, then you should use the title to get the body from cache.
https://docs.cocos.com/cocos2d-x/handbook/en/sprites/spriteframe_cache.html
The following 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<SpriteBody*>record;
record.reserve(2);
record.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10020.png"));
record.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10021.png"));
auto pAnimation = Animation::createWithSpriteFrames(record, 0.2f, 1000);
auto pAnimate = Animate::create(pAnimation);
pSprite2->runAction(pAnimate);
But the error within the title seems after operating. doesn’t remedy the issue.
[ad_2]