[Solved] - CCSpriteBatchNode Asserts "CCSprite is not using the same texture id"

Ok, before I start, yes I know the cause. The texture ids do not match. Thing is, I am under the impression that I’m doing the right thing, and this shouldn’t be happen.

In the directory, I have a set of png files:
test1.png

test10.png

accompanied by .plist files:
test1.plist

test10.plist

+These have been generated by TexturePacker. I’ve gone into the plist files, and for each of them, the metadata~~>textureFileName checks out:+
test1.plist~~>metadata~~>textureFileName = test1.png

test10.plist~~>metadata~~>textureFileName = test10.png
At the beginning of the game scene, I preload everything like so:
<pre>
//I don’t have an itoa.
std::stringstream ss;
for
{
std::string strNum;
ss << i;
ss >> strNum;
std::string filepath = “test” + strNum “.png”;
std::string plistpath = “test”
strNum +“.plist”;
CCSpriteBatchNode* spriteSheet = CCSpriteBatchNode::create);
//where allSpriteSheets is a CCArray* of SpriteBatchNode, so I can use it later.
allSpriteSheets~~>addObject(spriteSheet);

//where baseLayer is a CCLayer* that is basically the first layer in the game scene.
baseLayer~~>addChild~~>getZOrder
);
CCSpriteFrameCache::sharedSpriteFrameCache~~>addSpriteFramesWithFile );
}

</pre>
later, I attempt to create a sprite using a frame already in the texture used in the CCSpriteBatchNode.
<pre>
CCSprite* sp = new CCSprite;
//I’m purposely setting the frame I want to use here. Every plist file has the exact same naming convention, so it shouldn’t matter which one I use at this point.
std::string initName = “IDL001.png”
//The name is correct, and in fact this frame appears in all plist files, despite the animation length being different.
sp~~>initWithSpriteFrameName);
//the very first SpriteBatchNode I added to the base layer. This exists and is valid, because allSpriteSheets only contain SpriteSheets with the same animation naming convention.
CCSpriteBatchNode* targetLayer = allSpriteSheets~~>objectAtIndex;
//Omitted: setting sprite position
//this line triggers the Assert.
targetLayer~~>addChild(sp);

I did a CCLog before the Assert, and found that the texture ids are indeed different; this didn’t happen when I used a non-plist method.

Did I forget something here?

Thanks in advance.

I don’t see where you are creating spriteRep which you use in your code in the line targetLayer->addChild(spriteRep);. Is it something like this: CCSprite* spriteRep = CCSprite::createWithSpriteFrameName(“texturename.png”); ?

Leszek X wrote:

I don’t see where you are creating spriteRep which you use in your code in the line targetLayer->addChild(spriteRep);. Is it something like this: CCSprite* spriteRep = CCSprite::createWithSpriteFrameName(“texturename.png”); ?

Whoops. Wrong variable. Renamed.
I meant to add the new sprite instance sp*.

Do you have this “IDL001.png” in more than one plist file because I don’t think that this is supported?

Leszek X wrote:

Do you have this “IDL001.png” in more than one plist file because I don’t think that this is supported?

…actually, yes. IDL001.png was supposed to be the name of the first frame for all animations.

I appended the file names in front of these, and resaved everything, and now I don’t get the Assert anymore.

Thanks!

Hi Larry Leow,
I notice the discussion is tagged with [SOLVED].
Can you tell me the root cause you find out and the way you solve it ?
I’m also having the same problem there.
Thanks in Advance.

Hi, check 2 responses above.

Turned out to be my problem. Different plist files cannot have the same frame name(s). I had to regenerate the plist files and add the name of the image sequence in front to differentiate them.