title: Cocos2d: Can't seem to create child sprites correctly using class or instance method
body: <p>I made a similar thread yesterday, but received barely any responses probably because of the lack of detail. I'm going to be a lot more thorough. </p>
  
  <p>So I've been cleaning up my class (JoinedMapsLayer) that has my tmx map added to it and running update, draw, etc. There are some methods that I've tried adding to other classes without complete success. Some create sprites and successfully display them on screen, but JoinedMapsLayer cannot seem to identify them any longer even though that's where they came from in it's header file. Therefor, I cannot use JoinedMapsLayer or some other class to remove it. I tried setting a breakpoint after it gets added (wherever it gets added) and type po [spritename] into the console, and it comes up nil.</p>
  
  <p>Maybe I just don't understand how this should work completely and I must be taking the wrong approach. If anyone could help me to understand this once and for all, it will be much appreciated!</p>
  
  <p>I've come across a good example where I've yet again had no success. This one is not showing up at all.</p>
  
  <p>Here I can show you what I used to have, that worked perfectly:</p>
  
  <p>(in .h) JoinedMapsLayer's interface I have:</p>
  
  <pre><code>CCSprite *selectionScreenOverlaySprite;
  CCSpriteBatchNode * selectionScreenOverlaySpriteSheet;
  </code></pre>
  
  <p>My properties:</p>
  
  <pre><code>@property(nonatomic, retain) CCSprite *selectionScreenOverlaySprite;
  @property(nonatomic, retain) CCSpriteBatchNode *selectionScreenOverlaySpriteSheet;
  </code></pre>
  
  <p>Declare method:</p>
  
  <pre><code>-(void) addSelectionScreenOverlay;
  </code></pre>
  
  <p>(In .m) I synthesize my properties:</p>
  
  <pre><code>@synthesize selectionScreenOverlaySprite, selectionScreenOverlaySpriteSheet;
  </code></pre>
  
  <p>My method:</p>
  
  <pre><code>-(void) addSelectionScreenOverlay {
  
      // overlay
  
      [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"selectionScreenOverlay.plist"];
  
      selectionScreenOverlaySpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"selectionScreenOverlay.png"];
  
      NSMutableArray *selectionScreenFrames = [NSMutableArray array];
  
      [selectionScreenFrames addObject:
       [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
        [NSString stringWithFormat:@"selectionScreenOverlay.png"]]];
  
      selectionScreenOverlaySprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"selectionScreenOverlay.png"]];  
  
      [selectionScreenOverlaySpriteSheet addChild:selectionScreenOverlaySprite];
  
      [self addChild:selectionScreenOverlaySpriteSheet z:13];
  
      selectionScreenOverlaySprite.position = [self convertToNodeSpace:CGPointMake(512, 384)];
      selectionScreenOverlaySprite.scale = 260;
  
      selectionScreenOverlaySprite.opacity = 0;
  
  }
  </code></pre>
  
  <p>So that works fine...</p>
  
  <hr>
  
  <p>But when I import a class called SpriteFX.h in my header and call the new method nothing happens???</p>
  
  <p>I do a call to the class method like this:</p>
  
  <pre><code>[SpriteFX addSelectionScreenOverlayOnLayer:self
                                  withSprite:selectionScreenOverlaySprite
                             withSpriteSheet:selectionScreenOverlaySpriteSheet];
  </code></pre>
  
  <p>And I have the method declared in SpriteFX.h like this:</p>
  
  <pre><code>+(void) addSelectionScreenOverlayOnLayer:(CCLayer*)layer
                                withSprite:(CCSprite*)sprite
                           withSpriteSheet:(CCSpriteBatchNode*)spriteSheet;
  </code></pre>
  
  <p>And my method in SpriteFX.m looks like this:</p>
  
  <pre><code>+(void) addSelectionScreenOverlayOnLayer:(CCLayer*)layer
                                withSprite:(CCSprite*)sprite
                           withSpriteSheet:(CCSpriteBatchNode*)spriteSheet {
  
      [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"selectionScreenOverlay.plist"];
  
      spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"selectionScreenOverlay.png"];
  
      NSMutableArray *selectionScreenFrames = [NSMutableArray array];
  
      [selectionScreenFrames addObject:
       [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
        [NSString stringWithFormat:@"selectionScreenOverlay.png"]]];
  
      sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"selectionScreenOverlay.png"]];  
  
      [spriteSheet addChild:sprite];
  
      [layer addChild:spriteSheet z:13];
  
      sprite.position = [layer convertToNodeSpace:CGPointMake(512, 384)];
      sprite.scale = 260;
  
      sprite.opacity = 0;
  }
  </code></pre>
  
  <p>no beans</p>
  
  <p>If I undersand correctly, since I'm passing self as a CCLayer, then layer in my class method should be pointing back to the CCLayer in JoinedMapsLayer. Also the sprite and sprite sheet that are passed should be pointing back to JoinedMapsLayer, so it should work all the same.. but it isn't. </p>
  
  <p>After the class method call in JoinedMapsLayer I checked the parent object on selectionScreenOverlaySprite. It is nil.</p>