Cocos2D - ccTouchBegan无法访问NSMutableArray?

时间:2011-07-03 19:29:06

标签: cocos2d-iphone nsmutablearray

首先,让我们清楚两件事。我的英语很糟糕,我在cocos2d中很新。很抱歉再次抱歉。 :D现在我的问题。

我已经在.m(它是一个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(unBoutontest.Valeur);

        cptLettres = cptLettres+1;
    } while (cptLettres < 16); 

问题是我的arrayBoutons似乎无法将我的数据保存在我的NsMutableArray中。

1 个答案:

答案 0 :(得分:2)

您是否初始化了NSMutableArray,可能是在init方法中?你需要打电话给:

arrayBoutons = [[NSMutableArray alloc] init];

然后,您需要在dealloc方法中释放它:

[arrayBoutons release];