Problem with adding sprite using CCSprite array in cocos2d -


i have problem following code.


myspritearray=[[nsmutablearray alloc] init];

star=[ccsprite spritewithfile:@"22.png"]; for(int i=0;i<10; i++) { [myspritearray insertobject:star atindex:i]; } // nslog(@"x=%i",[myspritearray count]); (int i=0; i<10; i++) // opponents nsmutablearray { ccsprite *tempsprite = (ccsprite *) [myspritearray objectatindex:i]; tempsprite.position=ccp(100,100); [self addchild:tempsprite]; }

} star object of ccsprite , myspritearray mutable array.the problem when run program crash , say

* assertion failure in -[gamescene addchild:z:tag:], /users/salimsazzad/desktop/balon hunter/libs/cocos2d/ccnode.m:305 2010-10-08 19:05:35.854 balon hunter[3967:207] * terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'child added. can't added again'.

i can't understand whats wrong,i adding 10 object,not 1 object in 10 times because ccsprite *tempsprite = (ccsprite *) [myspritearray objectatindex:i];creating new object each time. problem???

you have created star object once , added 10 times array:

star=[ccsprite spritewithfile:@"22.png"]; for(int i=0;i<10; i++)  {     [myspritearray insertobject:star  atindex:i]; } 

so array contains same object , that's reason of assertion get.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -