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