Note that there are some explanatory texts on larger screens.

plurals
  1. POSprite not visible at times
    primarykey
    data
    text
    <p>I have a cocos2d based iphone app with a problem. When the user pauses the game and then hits the resume button, some CCSprites will disappear from the screen. This behavior is random, no pattern followed. I just know that this only happens when the user resumes the game.</p> <p>Here is the code, what am I doing wrong? I first thought it might be a memory management problem, but I never get any EXC_BAD_ACCESS when the user hits resume... So the sprites probably still exist.</p> <p>The sprites are a property within an object I'll call "myobject".</p> <p>In myObject.h I have:</p> <pre><code>@interface myObject : CCNode{ CCSprite *_sprite1,*_sprite2; // some other code } @property (nonatomic,retain) CCSprite *sprite1,*sprite2; </code></pre> <p>And in myObject.m file:</p> <pre><code>@synthesize sprite1=_sprite1; @synthesize sprite2=_sprite2; +(id)create:(CCLayer*)scene{ myobject.sprite1 = [CCSprite spriteWithFile:spriteFile]; [scene addChild:myobject.sprite1]; // same for sprite2 } -(void) move:(ccTime)dt{ //SOMECODE self.sprite1.position=ccp(self.x,self.y); // same for sprite2 } </code></pre> <p>then they get moved around with a function called on the myobject.</p> <p>In the main scene, here is how these objects are created and moved around:</p> <pre><code>myObject *myObject; NSMutableArray *_myObjects; @implementation HelloWorld +(id) scene { CCScene *scene = [CCScene node]; HelloWorld *layer = [HelloWorld node]; [scene addChild:layer z:0 tag:33]; return scene; } -(id) init { if( (self=[super init] )) { _myObjects = [[NSMutableArray alloc] init]; // some other code } } -(void) addObject(){ myObject=[myObject create:self]; [_fallingObjects addObject:fallingObject]; } -(void) nextFrame:(ccTime) dt{ for(myObject *theObject in _myObjects){ [theObject move:dt]; } } // And here is the function that does the pause/unpause, here it is: - (void) pauseGame{ if(pauseStatus==0){ [[CCDirector sharedDirector] pause]; pauseStatus=1; // some code to display menu etc... such as: [self addChild:pauseMenu z:10]; } else{ [self removeChild:pauseMenu cleanup:YES]; [self removeChild:scoreLabel cleanup:YES]; [self removeChild:highscoreLabel cleanup:YES]; [self removeChild:titleLabel cleanup:YES]; [self removeChild:pauseLayer cleanup:YES]; [[CCDirector sharedDirector] resume]; pauseStatus=0; } } </code></pre> <p>==EDIT===</p> <p>I have discovered that this problem is also true for sprites that I add directly to my scene, such as the sprite clown added as shown below:</p> <pre><code>CCSprite *clown; @implementation HelloWorld -(id) init { if( (self=[super init] )) { // some code clown = [[CCSprite spriteWithFile:@"clown.png"] retain]; [self addChild:clown z:2]; // some more code } } @end </code></pre> <p>==END OF EDIT===</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload