ios - optimize animation in cocos2d failed -



ios - optimize animation in cocos2d failed -

when didn't optimize animation,it worked well.but when optimized animation,the programme crashed.and xcode log said:

assertion failure in -[ccspritebatchnode addchild:z:tag:], /users/hanpengbo/documents/xcode/cocos2d_helloworld/cocos2d_helloworld/libs/coco‌​s2d/ccspritebatchnode.m:183

in ccspritebatchnode.m:183,there is

nsassert( child.texture.name == textureatlas_.texture.name, @"ccsprite not using same texture id");

here code

// cache ccspriteframecache *cache=[ccspriteframecache sharedspriteframecache]; [cache addspriteframeswithfile:@"birdatlas.plist"]; // frame array nsmutablearray *framesarray=[nsmutablearray array]; (int i=1; i<10; i++) { nsstring *framename=[nsstring stringwithformat:@"bird%d.png", i]; id frameobject=[cache spriteframebyname:framename]; [framesarray addobject:frameobject]; } // animation object id animobject=[ccanimation animationwithframes:framesarray delay:0.1]; // animation action id animaction=[ccanimate actionwithanimation:animobject restoreoriginalframe:no]; animaction=[ccrepeatforever actionwithaction:animaction]; // sprite cocosguy = [ccsprite spritewithfile: @"icon.png"];//cocosguy ccsprite,declared earler cocosguy.position = ccp( 200, 300 ); // batchnode ccspritebatchnode *batchnode=[ccspritebatchnode batchnodewithfile:@"birdatlas.png"]; [self addchild:batchnode]; [batchnode addchild:cocosguy]; [cocosguy runaction:animaction];

update: here corrected code,and works well

// batchnode ccspritebatchnode *batchnode=[ccspritebatchnode batchnodewithfile:@"birdatlas.png"]; [cocosguy settexture:[batchnode texture]]; [self addchild:batchnode]; [batchnode addchild:cocosguy];

for work, icon.png texture should in birdatlas.png texture, appropriate declaration in .plist. batchnodes 1) created 1 texture (and one), , 2) take children sprites same texture.

... , , dont know intent, typically have

ccsprite *cocosguy = [ccsprite spritewithspriteframe:[cache spriteframebyname:@"bird1.png"];

in case, think batch node add together work.

... , , not sure using batch node of consequence animation, if texture contains animation frames 1 animation. frames displayed 1 @ time, dont think benefit batched draw call.

ios cocos2d-iphone

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -