I have a background that extends CCSprite
from the cocos2d framework. And I have added this sprite to the gamelayer. Now in this background class I try to add other CCSprites
named Star like so:
//create the stars
stars = [[CCArray alloc] init];
for (int i = 0; i < 10; i++)
{
Star* star = [[Star alloc ] initWithFile:@"star-hd.png"];
CGSize screensize = [[CCDirector sharedDirector] winSize];
//CCLOG(@"screensize: %f, %f", screensize.width, screensize.height);
CGPoint newstarlocation;
newstarlocation.x = CCRANDOM_0_1() * screensize.width;
newstarlocation.y = CCRANDOM_0_1() * screensize.height;
star.position = newstarlocation;
[self addChild:star z:i];
[stars addObject:star];
}
but the stars won't show. I tried several things and the only thing that seems to work is when I add the stars on the gamelayer instead of the background. but that is not what I want.
is it not allowed in cocos2d to nest sprites? and if it is allowed, how do I nest sprites?