Okay I had a problem that I post yesterday which wasn’t the real problem I guess. The thing is, when I do my first NSLOG, it shows me that the array length is 3. Then I had the object Snake (which contains two arrays and is a subclass of CCSprite), to the array body. Then, always in the same init, the two last NSLOG, which are the same as the first two, tell me that my two arrays have now a length of 0. I don’t understand what’s going on. Help please!
-(id)init{
if ((self = [super initWithColor:ccc4(255, 255, 255, 255)] ))
{
SnakePart * snake;
snake = [[SnakePart alloc]init];
body = [[NSMutableArray alloc] init];
NSLog(@"Grandeur du tableau : %i", [[snake arrayOfDirectionChangingPoint] count]);
NSLog(@"Grandeur du tableau : %i", [[snake arrayOfPartDirection] count]);
CGSize winSize = [[CCDirector sharedDirector] winSize];
direction = HAUT;
snake = [SnakePart spriteWithFile:@"snakeMainSquare.png"];
snake.position = ccp(winSize.width/2, winSize.height/2 - 75);
[self addChild:snake];
[body addObject:snake];
[self addBodyPart:snake.position.x :(snake.position.y - (snake.contentSize.height * (body.count)))];
[self addBodyPart:snake.position.x :(snake.position.y - (snake.contentSize.height * (body.count)))];
SnakePart* head = ((SnakePart*)body[0]);
NSLog(@"Grandeur du tableau : %i", [[head arrayOfDirectionChangingPoint] count]);
NSLog(@"Grandeur du tableau : %i", [[head arrayOfPartDirection] count]);
I just found it myself. I changed the line :
to:
I guess the spriteWithFile was kind of erasing my arrays of snake since it’s like an init.