i’m working on some sample game using cocos2d to get more practise and I have a problem with classes. Here’s my example:
someShapes.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface palleteOfShapes : CCLayer
{
NSMutableArray *shapesArray;
}
@property (nonatomic,retain) NSMutableArray *shapesArray;
-(void)drawPallete;
@end
someShapes.m
#import "palleteOfShapes.h"
@implementation palleteOfShapes
@synthesize shapesArray;
-(void)drawPallete
{
shapesArray = [NSMutableArray arrayWithObjects:@"Icon.png",@"A.png",@"questionMark.png",nil];
for (int i=0; i<shapesArray.count; i++) {
NSString *imagestring = [shapesArray objectAtIndex:i];
CCSprite *sprite = [CCSprite spriteWithFile:imagestring];
NSLog(@"i value: %i",i);
sprite.position=ccp(100*i,350);
NSLog(@"image added:%@",imagestring);
[self addChild:sprite];
NSLog(@"count: %d",[shapesArray count]);
}
NSLog(@"pallete was completed");
[shapesArray removeLastObject];
NSLog(@"count:%d",[shapesArray count]);
}
@end
in the main layer I do:
palleteOfShapes *newPallete = [[palleteOfShapes alloc]init];
[newPallete drawPallete];
I expected that these sprites will appear on my main layer, but they don’t.
NSLog shows all messages but no sprites.
So if you can, please tell me what’s wrong.
thanks in advance.
You add sprites to “palleteOfShapes” layer, but you never add them or “palleteOfShapes” to main layer.