如何在二维数组里添加节点对象，求指导

sylalak123
Fri, 19 Jun 2015 02:46:15 +0000

谢谢版主的回复，但是，我直接取得点坐标，也是零！

打杠的位置输出的是零，本来想先用数组来实现，然后用vector来改的，stl 不太熟 ，看来要搞vector了

void HelloWorld::addBlock(){

    //添加批处理精灵

    auto batBlock = SpriteBatchNode::create("block.png", 81);
    addChild(batBlock);

    for (int n = 0; n < 9; n++){
        bool isdouble = true;

        for (int m = 0; m < 9; m++){

            if (isdouble){

                //创建精灵

                auto blockwhite1 = Sprite::createWithTexture(batBlock->getTexture(), CCRectMake(BLOCK_W , 0, BLOCK_W, BLOCK_H ));
                blockwhite1->setPosition(Vec2(i * 34 - 12 + 34, 28 * m + 28 + 28));
                batBlock->addChild(blockwhite1);

                //将方块放入数组中
                HelloWorld::getarrayBlock()->addObject(blockwhite1);

                arrayBlocks   = blockwhite1;
                arrayBlocks  ->setPosition(Vec2(i * 34 - 12 + 34, 28 * m + 28 + 28));

    ///////////////            CCLOG("arrayBlocks x is %d", arrayBlocks ->getPositionX());
                isdouble = false;
            }
            else{
                //创建精灵
                auto blockwhite2 = Sprite::createWithTexture(batBlock->getTexture(), CCRectMake(BLOCK_W, 0, BLOCK_W, BLOCK_H ));
                blockwhite2->setPosition(Vec2(i * 34 - 11 + 16 + 34, 28 * m + 28 + 28));
                batBlock->addChild(blockwhite2);

                //将方块放入数组中
                HelloWorld::getarrayBlock()->addObject(blockwhite2);

                arrayBlocks = blockwhite2;
                arrayBlocks->setPosition(Vec2(i * 34 - 11 + 16 + 34, 28 * m + 28 + 28));

                isdouble = true;
            }

        }

    }


}


```

阅读整个主题