开发者

memory allocation when using CCSprite array in cocos2d-android-1

开发者 https://www.devze.com 2023-03-11 08:51 出处:网络
I am using cocos2d-android-1 for my gamedevelopment. I have some confusion related to memory allocation.

I am using cocos2d-android-1 for my gamedevelopment. I have some confusion related to memory allocation. Suppose I need an array of sprites. I will declare them as

CCSprite mySprites = new CCSprite[MAX_SPRITES];

and while creating i will create them and add to current layer like:

for(int i=0;i<MAX_SPRITES;i++)
{
    mySprites[i] = CCSprite.sprite("image_"+i+".png");
    this.addChild(mySprites[i]);
}

Now sprites are added to layer but we need to access them while game flow so we will use mySprites; So my question is when we do this.removeAllChildren(true); for this layer, will it remove all children and also mySprites sprites? Or do we need to do something like this

for(int i=0;i<MAX_SPRITES;i++)
{
    mySprites[i] = null;
}

In my game I think memory is leaking if there is simillar case.

We can also use tags to retrive sprites instead of using

CCSprite mySprites = new CCSprite[MAX_SPRITES];.

Ple开发者_开发技巧ase can you tell me what is the solution for this?

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消