2011-11-11 11 views
0

5秒ごとにオブジェクトをドロップしたい。私の問題は、画面に最初に登場する動物が落ちるのですが、それ以降の動物は元の姿勢に固執しません。5秒ごとに落ちるスプライト

動物を落とすための私のコードは次のとおりです。

-(void)dropAnimal 
{ 
    [self performSelector:@selector(dropAnimal) withObject:nil afterDelay:5]; 
    prevojectIndex=objectIndex; 
    prevIndex=currentIndex; 

    float padding = sw*128/768; 
    float x = (float)(arc4random()%(int)(sw-padding*2))+padding; 

    if([SpritesARRAY count]>0) 
    { 
     objectIndex=arc4random()%[SpritesARRAY count]; 
     object=[SpritesARRAY objectAtIndex:objectIndex]; 
     object.falling = YES; 
     currentIndex=arc4random()%[animalsArray count]; 
     [object initWithSpriteFrameName:[animalsArray objectAtIndex:currentIndex]]; 
     object.position = ccp(x, sh*31/32-self.position.y); 

     objectsDictionary=[NSMutableDictionary dictionary]; 
     [objectsDictionary setObject:object forKey:[[NSNumber numberWithInt:objectIndex] stringValue]]; 
     [objectsDictionary retain]; 
     [SpritesARRAY removeObjectAtIndex:objectIndex]; 
     [self animateAnimal]; 

    }  
} 

-(void) animateAnimal 
{ 
    FallAnimal *CurObject=[objectsDictionary objectForKey:[[NSNumber numberWithInt:objectIndex] stringValue]]; 
    [CurObject runAction:[CCMoveTo actionWithDuration:2 position:CGPointMake(CurObject.position.x,90)]]; 
     [CurObject release]; 
    } 

答えて

0

あなたはここにCurObjectを解放しないでください。

-(void) animateAnimal 
{ 
    FallAnimal *CurObject=[objectsDictionary objectForKey:[[NSNumber numberWithInt:objectIndex] stringValue]]; 
    [CurObject runAction:[CCMoveTo actionWithDuration:2 position:CGPointMake(CurObject.position.x,90)]]; 
    [CurObject release]; // <-- makes no sense, you did not retain it! 
} 
+0

を私はCurObjectを解放していないよ場合...問題は同じです。あなたは主な問題が何であるか知っていますか? – Neha

+0

その他のメモリ管理の問題については、コードを確認してください。メモリ管理を正しく理解していないため、あらゆる種類の問題を抱えている可能性があります。 Xcodeで "Product - > Analyze"を実行すると、コンパイラがそのようなケースを見つける手助けをすることができます。 – LearnCocos2D

関連する問題