void BubbleGrid::buildGrid() { // Create the array with the rows m_pBubbles = new Bubble**[GRID_WIDTH]; // Fill each row with the cols for(int i = 0; i < GRID_WIDTH; i++) m_pBubbles[i] = new Bubble*[GRID_HEIGHT]; CCSize size = CCDirector::sharedDirector()->getWinSize(); float startingPosX = BUBBLE_RADIUS; float startingPosY = size.height - BUBBLE_RADIUS; // fill the 2D array wiht bubbles for (int i = 0; i < GRID_WIDTH; i++) { for (int j = 0; j < GRID_HEIGHT; j++) { Bubble *bubble = Bubble::create(); bubble->setPosition(getPosition(i, j)); if(j < GRID_HEIGHT_START) { bubble->setType((BUBBLE_TYPE)((int)((CCRANDOM_0_1() * 4) + 1))); if(j % 2 != 0) { if(i == GRID_WIDTH - 1) // odd rows have 1 less bubble bubble->setType(EMPTY); } } else { bubble->setType(EMPTY); } this->addChild(bubble); m_pBubbles[i][j] = bubble; } } }
Bubble * Bubble::initWithType(BubbleType type) //根据传过来的类型来生成泡泡 { Bubble *pRet = Bubble::create(); pRet->setType(type); pRet->initWithSpriteFrameName(getStringByType(type)); return pRet; }