0

I want to drop some objects after every 5 seconds. My problem is that, the animal which is first to come up on the screen falls but the animals after that do not fall they stuck to their original positions.

my code for dropping animal is:

-(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];
  }
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
Neha
  • 167
  • 1
  • 11

1 Answers1

0

You shouldn't release CurObject here:

-(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!
}
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • If I'm not releasing the CurObject.. the problem is same. Do you know what is the main problem?? – Neha Nov 14 '11 at 04:05
  • Check your code for other memory management issues. You could be having all kinds of problems because of not properly understanding memory management. Run "Product -> Analyze" in Xcode to let the compiler help you find such cases. – CodeSmile Nov 14 '11 at 19:16