0

I have a class called Projectiles which inherits from CCSprite class, Currently there are 2 types of projectiles, rain1 and rain2. I have a method that creates a bunch of these sprites every 2 seconds to give the illusion of pulsating rain. Each one of these rain sprites is added to the array, _projectiles and it is effected by gravity.

In fact, its working just about perfectly, except for the memory management and soon after this rain loop keeps creating sprites I get massive frame rate drops.

Ideally, if the rain (under the constant of gravity) drops below the height of the screen, I want the rain sprite to be deleted. Deleted from the _projectiles array, deleted from the view completely!

My code isn't doing this! Please I need some assistance...

Here is a snippet:

for (Projectile *rain1 in _projectiles){
    if (rain1.position.y < -winSize.height) {
        rain1 = nil;
        [_projectiles removeObject: rain1];
        [self removeChild:rain1 cleanup:YES];
        [rain1 release];

    }
}

for (Projectile *rain2 in _projectiles){
    if (rain2.position.y < -winSize.height) {
        rain2 = nil;
        [_projectiles removeObject: rain2];
        [self removeChild:rain2 cleanup:YES];
        [rain2 release];
    }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ospho
  • 2,756
  • 5
  • 26
  • 39

1 Answers1

1

remove the rain1 = nil, that should work. you change the rain1 pointer to nil, thats why when you call [self removechild] it cannot find the rain1 sprite to remove.

Lim Gim Hong
  • 306
  • 1
  • 3
  • It works now, Thanks. But I still experience a drop in frames when deleting multiple sprites? for example, if i wanted to delete 15 rain particles/sprites all within a second of eachother, it generates lag? – Ospho Feb 22 '11 at 06:16
  • Please see this thread: http://stackoverflow.com/questions/5074999/removing-many-ccsprites – Ospho Feb 22 '11 at 06:54