我必须从plist加载屏幕上的图像,我使用以下代码
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("level1.plist");
CCSpriteBatchNode *bgBatch = CCSpriteBatchNode::batchNodeWithFile("level1.png");
this->addChild(bgBatch);
CCSprite *bg = CCSprite::spriteWithSpriteFrameName("jug.png");
bg->setPosition(ccp(30,115));
bgBatch->addChild(bg);
但不推荐使用函数“batchNodeWithFile”和“spriteWithSpriteFrameName”。我应该使用哪些功能而不是这些功能?
感谢您的帮助,但我试过这个,但是当我运行它时
感谢您的帮助,但我试过这个,当我运行它时
CCSprite* CCSprite::createWithSpriteFrameName(const char *pszSpriteFrameName)
{
CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()- >spriteFrameByName(pszSpriteFrameName);
#if COCOS2D_DEBUG > 0
char msg[256] = {0};
sprintf(msg, "Invalid spriteFrameName: %s", pszSpriteFrameName);
CCAssert(pFrame != NULL, msg); /* it stops right here and gives error "Assertion failed: (pFrame != __null), function createWithSpriteFrameName, file /Users/gameview/Desktop/mahwish/mahwish/libs/cocos2dx/sprite_nodes/CCSprite.cpp, line 158."
#endif
我做错了什么?
答案 0 :(得分:-1)
Cocos2d-x中的静态构造函数已重命名,因此它们都以create
开头,所以
CCSpriteBatchNode::batchNodeWithFile
仅转向 CCSpriteBatchNode::create
CCSprite::spriteWithSpriteFrameName
转向 CCSprite::createWithSpriteFrameName