vendredi 29 avril 2016

Cocos2d-x multidimensional array of Node *

Cocos2d-x 3.10

I need to create a 5x5 node matrix (array). So:

Node *n[5][5];
for (int x = 0; x < 5; x++) {
    for (int y = 0; y < 5; y++) {
        n[x][y] = Node::create();
        n[x][y]->setTag(0);
    }
}

void replaceMatrix() {
    Node *u[5][5];
    for (int x = 0; x < 5; x++) {
        for (int y = 0; y < 5; y++) {
            u[x][y] = Node::create();
            u[x][y]->setTag(0);
        }
    }
    **n = **u;
}

At some point during game play I need to replace this matrix with another (from a function call). My question is; how do I manage memory here? Simply replacing **n = **u won't release or free the nodes. I could call n[x][y]->release(); but is that all I need to do? Or, do I need to also free **n in some way?

I'm coming from heavy Java and C# skills and I use to do a lot of ObjC (pre ARC) programming in the day. I understand Cocos2d-x implements the Retain/Release model. I think my confusion comes from using Cocos2d-x Objects with a std C++ 2D array.

Aucun commentaire:

Enregistrer un commentaire