void PauseLayer::createLabel(const char *labelName, const char *labelNameValue, CCPoint position, CCSprite *objective) { float scale = Utility::isIPad() ? 1 : 0.5; CCLabelBMFont *label = CCLabelBMFont::create(labelName, kFontChubby, 0, kCCTextAlignmentLeft); label->setPosition(position); label->setScale(scale); label->setAnchorPoint(ccp(0, 1)); objective-> addChild(label, 10); CCLabelBMFont *labelText = CCLabelBMFont::create(labelNameValue, kFontChubby, winSize.width * 0.4); // labelText-> labelText->setPosition(ccp(label->getPositionX(), label->getPositionY() - winSize.height * 0.078 )); labelText->setScale(scale * 0.65); labelText->setAnchorPoint(ccp(0, 1)); objective->addChild(labelText, 10); }
void GameScene::showScore() { //スコア CCLabelBMFont* score = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagScore)); if (score) { score->removeFromParent(); } CCLabelBMFont* label = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagScoreLabel)); CCString* gameScore = CCString::createWithFormat("%d", getScore()); score = CCLabelBMFont::create(gameScore->getCString(), FONT_ORANGE); score->setScale(TEXT_SCALE); score->setAnchorPoint(CCPointZero); score->setPosition( label->getPositionX() + label->getContentSize().width * TEXT_SCALE + 10, label->getPositionY()); score->setTag(kTagScore); this->addChild(score); }
void GameScene::showBallRemain() { //残りボール数 CCLabelBMFont* remain = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagBallRemainCount)); if (remain) { this->removeChild(remain); } CCLabelBMFont* label = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagBallRemainLabel)); CCString* ballRemain = CCString::createWithFormat("%d", getBallRemain()); remain = CCLabelBMFont::create(ballRemain->getCString(), FONT_ORANGE); remain->setScale(TEXT_SCALE); remain->setAnchorPoint(CCPointZero); remain->setPosition( label->getPositionX() + label->getContentSize().width * TEXT_SCALE + 10, label->getPositionY()); remain->setTag(kTagBallRemainCount); this->addChild(remain); }
bool GameLayer::init() { if (!CCLayer::init()) { return false; } // 开启触摸 this->setTouchEnabled(true); // 创建数组,需要retain一下 play_bullet = CCArray::create(); play_bullet->retain(); enemy_bullet = CCArray::create(); enemy_bullet->retain(); enemy_items = CCArray::create(); enemy_items->retain(); m_state = statePlaying;//statePlaying=0 Enemy::sharedEnemy(); Effect::sharedExplosion(); Config::sharedConfig()->resetConfig(); winSize = CCDirector::sharedDirector()->getWinSize(); m_levelManager = new LevelManager(this); //初始化背景 initBackground(); m_screenRec = CCRectMake(0, 0, winSize.width, winSize.height + 10); // score CCLabelBMFont *scoreLabel = CCLabelBMFont::create("SCORE: ", s_arial14_fnt); scoreLabel->setAnchorPoint(ccp(0, 0)); addChild(scoreLabel, 1000); scoreLabel->setColor(ccc3(255, 240, 188)); scoreLabel->setPosition(100, winSize.height - 30); { // 1 1 000 m_lbScore1 = CCLabelBMFont::create("", s_arial14_fnt); m_lbScore1->setAnchorPoint(ccp(0, 0)); m_lbScore1->setColor(ccc3(200,0,200)); addChild(m_lbScore1, 1000); m_lbScore1->setPosition(scoreLabel->getPositionX()+scoreLabel->getContentSize().width, scoreLabel->getPositionY()); // m_lbScore2 = CCLabelBMFont::create("", s_arial14_fnt); m_lbScore2->setAnchorPoint(ccp(0, 0)); m_lbScore2->setColor(ccYELLOW); addChild(m_lbScore2, 1000); m_lbScore2->setPosition(m_lbScore1->getPositionX()+m_lbScore1->getContentSize().width, m_lbScore1->getPositionY()); // m_lbScore3 = CCLabelBMFont::create("", s_arial14_fnt); m_lbScore3->setAnchorPoint(ccp(0, 0)); addChild(m_lbScore3, 1000); m_lbScore3->setPosition(m_lbScore2->getPositionX()+m_lbScore2->getContentSize().width, m_lbScore2->getPositionY()); } // ship life CCTexture2D *shipTexture = CCTextureCache::sharedTextureCache()->addImage(s_ship01); CCSprite *life = CCSprite::createWithTexture(shipTexture, CCRectMake(0, 0, 60, 38)); life->setScale(0.6); life->setPosition(ccp(30,winSize.height-23)); addChild(life, 1, 5); // ship life count char lifecount[2]; sprintf(lifecount, "%d",Config::sharedConfig()->getLifeCount()-1); m_lifeCount = CCLabelTTF::create(lifecount, "Arial", 20); m_lifeCount->setPosition(ccp(60, winSize.height-20)); m_lifeCount->setColor(ccc3(255,0, 0)); addChild(m_lifeCount, 1000); // ship m_ship = Ship::create(); addChild(m_ship, m_ship->getZoder(), 1001); //pause CCMenuItemImage *pause = CCMenuItemImage::create("pause.png", "pause.png", this, menu_selector(GameLayer::doPause)); pause->setAnchorPoint(ccp(1, 1)); pause->setScale(0.8); pause->setPosition(ccp(winSize.width, winSize.height)); CCMenu *menu = CCMenu::create(pause, NULL); menu->setAnchorPoint(ccp(0, 0)); addChild(menu, 1, 10); menu->setPosition(CCPointZero); // 调 update函数 scheduleUpdate(); // 每秒调一次 scoreCounter函数 schedule(schedule_selector(GameLayer::scoreCounter), 1); if (Config::sharedConfig()->getAudioState()) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_bgMusic, true); } return true; }