Cocos2D - NSMutableArray not accessible in ccTouchBegan?
First, let's be clear on two things. My English is terrible and I'm pretty new in cocos2d. So sorry and sorry again. :D Now for my question.
I have declared these in a .m (Its a CCscene):
//A mutable array global to my class
NSMutableArray *arrayBoutons;
//I use this array like this :
LettreBleue *lettre1 = nil;
lettre1 = [LettreBleue construireObjLettre];
lettre1.position = ccp(80,370);
[self addChild:lettre1];
[arrayBoutons addObject:lettre1];
//The method to register the touch
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:kCCMenuTouchPriority swallowsTouches:NO];
}
// The classic TouchBegan in which Im trying to access the value Valeur
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
// test!
NSLog(@"Debut test ccTouchBegan4");
int cptLettres = 0;
do {
LettreBleue *unBoutontest=[arrayBoutons objectAtIndex: cptLettres];
NSLog(unBou开发者_如何学Gotontest.Valeur);
cptLettres = cptLettres+1;
} while (cptLettres < 16);
The problem is my arrayBoutons
doesn't seem to keep my data in my NsMutableArray
.
Have you initialized the NSMutableArray, perhaps in an init method? You need to call something like:
arrayBoutons = [[NSMutableArray alloc] init];
Then, you need to release it in your dealloc method:
[arrayBoutons release];
精彩评论