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];
}
如果我不釋放CurObject ..問題是一樣的。你知道什麼是主要問題? – Neha
檢查您的代碼是否存在其他內存管理問題。由於沒有正確理解內存管理,你可能會遇到各種各樣的問題。在Xcode中運行「產品 - >分析」讓編譯器幫助您找到這種情況。 – LearnCocos2D