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

sylalak123
Fri, 19 Jun 2015 06:14:55 +0000

用vector 解决了 ， 。追加一个问题：

加杠的地方，输出的值为什么是0 ？

void HelloWorld::addBlock(){

//添加批处理精灵

auto batBlock = SpriteBatchNode::create("block.png", 81);
//batBlock->setPosition(Vec2(0, 0));
addChild(batBlock);

auto & vecBlock = HelloWorld::getvecBlock();

for (int i = 0; i < 9; i++){
    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); 和下面的方法一样

            vecBlock.pushBack(blockwhite1);

//////////////// CCLOG(“blockwhite1 x is %d”, blockwhite1->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);

            vecBlock.pushBack(blockwhite2);

            isdouble = true;
        }

    }

}

}

阅读整个主题