Exemple #1
0
// ラベルの初期表示
void Game::showLabel()
{
    Size bgSize = m_background->getContentSize();
    
    // 残数表示
    // ラベルのタグ
    int tagsForLabel[] = {kTagRedLabel, kTagBlueLabel, kTagYellowLabel, kTagGreenLabel, kTagGrayLabel};
    // フォントファイル
    const char* fontNames[] = {FONT_RED, FONT_BLUE, FONT_YELLOW, FONT_GREEN, FONT_GRAY};
    // 表示位置(高さ)
    float heightRate[] = {0.61, 0.50, 0.39, 0.28, 0.17};

    // コマ種類のループ
    vector<kBlock>::iterator it = blockTypes.begin();
    while (it != blockTypes.end()) {
        // コマ残数表示
        // コマのタグを種類毎に保持している配列のサイズを取得
        int count = (int)m_blockTags[*it].size();
        // コマ残数をstring型にする config.hで定義済み
        const char* countStr = ccsf("%02d", count);

        // ラベルのタグよりインスタンスを取得 (アプリ起動直後はない)
        Label* label = (Label*)m_background->getChildByTag(tagsForLabel[*it]);
        
        // タグが取得できない場合true (アプリ起動直後)
        if (!label)
        {
            // 起動直後に通る

            // 画像のタグよりインスタンスを取得
            kBlock blockType = (kBlock)(*it);
            BlockSprite* blockSprite = (BlockSprite*)m_background->getChildByTag(blockType);
            // スプライト(図形や画像)を作成(画像などを指定)
            auto sprite = Sprite::create(blockSprite->getBlockImageFileName(blockType));
            sprite->setPosition(Point(bgSize.width * 0.74, bgSize.height * heightRate[*it]));
            // 画像を背景のスプライトに組み込み
            m_background->addChild(sprite,kZOrderLabel, blockType);

            
            
            
            // コマ残数生成 ラベル作成
            label = Label::createWithBMFont(fontNames[*it], countStr);
            label->setPosition(Point(bgSize.width * 0.8, bgSize.height * heightRate[*it]));
            m_background->addChild(label, kZOrderLabel, tagsForLabel[*it]);
            
        }
        else
        {
            // 文字列の更新
            label->setString(countStr);
        }
        it++;
    }
    // スコアを表示
    // スコアのstringを取得
    const char* scoreStr = ccsf("%02d", m_score);
    // ラベルのタグよりインスタンスを取得
    Label* scoreLabel = (Label*)m_background->getChildByTag(kTagScoreLabel);
    if (!scoreLabel) {
        // スコアラベル生成
        scoreLabel = Label::createWithBMFont(FONT_WHITE, scoreStr);
        // 場所決め
        scoreLabel->setPosition(Point(bgSize.width * 0.78, bgSize.height * 0.75));
        // 配置
        m_background->addChild(scoreLabel,kZOrderLabel,kTagScoreLabel);
    }
    else
    {
        // string型のスコアを変更
        scoreLabel->setString(scoreStr);
    }
    
}