iphone - CCSprites in NSMutableArray does not reappear after scene change -
i making game , putting ccsprites in nsmutablearray.
when start game first time sprites appearing on screen, seems work fine. when alter scene , come back, none of sprites visible on screen. here below code initialize sprites.
-(void spritesinit) gpsusersspritesarray = [[nsmutablearray alloc]init]; (int = 0 ; < [userarray count] ; i++){ playersprite = [ccsprite spritewithfile:@"greenspot.png"]; playersprite.position = ccp( winsize.width/2, winsize.height/2); [self addchild:playersprite z:5]; [gpsusersspritesarray addobject:playersprite]; [playersprite release]; } } the above method run every time scene called.
i run action below on sprites, works fine first time, 1 time again not when leave , homecoming scene. sprites seems loaded , code itterates through nsmutablearray in question without crash, , leaves me puzzled.
for (ccsprite *userspot in gpsusersspritesarray){ id fadein = [ccfadeto actionwithduration:0.05 opacity:255]; id fadeout = [ccfadeto actionwithduration:dotfadetime opacity:30]; id seq2 = [ccsequence actions:fadein, fadeout,nil ]; [userspot runaction:seq2]; } i have tried retain nsmutablearray, dit not help either. have tried forcefulness sprites visible , create sure opacity of sprites set 255, still no luck.
i may have overlooked something, not think so.
who helps me out?
many in advance.
you should not releasing sprite. think cause crash business relationship issue.
when create sprite using like:
ccsprite* mysprite = [ccsprite spritewithfile:@"whatever.png"]; you never should releasing that. when coding in objective-c rule remember when not using arc release objects alloc/init, new, retain, , re-create yourself. don't in illustration code. within method calls autorelease, making release invalid. same adding objects containers. containers take care of , should not releasing or doing retain count outside of containers on behalf if using convenience methods phone call autorelease, in case. invalid. fine if using, example, alloc/init rather spritewithfile method.
iphone cocos2d-iphone nsmutablearray ccsprite
No comments:
Post a Comment