Removing an object from a list

I have the following class:

public class PointBubble : CCNode
{
...
}

In my gamelayer I create a list of bubble objects:

public class GameLayer : CCLayerColor
    {
        List<PointBubble> PointBubbles;

        protected override void AddedToScene ()
        {
            ...
            PointBubbles = new List<PointBubble>();

            for (int i = 0; i < 30; i++) {
                PointBubbles.Add (new PointBubble());
            }
        }
        ...
    }

I then add my list of PointBubbles to the scene by looping through and doing:

this.AddChild (PointBubbles[i]);

Later in my game logic I need to pop a bubble. I loop through and check if a bubble's pop flag is set:

foreach (var PointBubble in PointBubbles) {
                    bool doesTouchOverlapBubble = PointBubble.BubbleSprite.BoundingBoxTransformedToWorld.ContainsPoint (TapLocation);
                    if (doesTouchOverlapBubble)
                    {
                        if (PointBubble.CheckPopped ())
                        {
                            ...
                            PointBubble.RemoveFromParent (true);
                            ...
                        }
                    }
                }

When I step through the code at runtime, after the call to RemoveFromParent I would expect the count of my PointBubbles to go down by one, but it doesn't. It stays at 30. What is the proper way to remove an object from the list and be removed from memory?

Best Answer

Answers

  • JaredMathesJaredMathes CAUniversity

    Thanks Rami. That does make sense.

Sign In or Register to comment.