bool GameSprite_Rice::init() { if (!CCSprite::init()) { return false; } this->setContentSize(CCSize(500, 70)); addRiceTime = RICEADDTIME; riceNum = 0; nowTime = 0; nowTime = this->getCurrentTime(); //字体背景. CCMenuItemImage *labelBgSprite = CCMenuItemImage::create(); labelBgSprite->setNormalSpriteFrame(GameShare_Texture::sharedTexture()->GetSpriteFrameByCCRect(akoomenu_image, CCRect(1763, 255, 120, 49))); labelBgSprite->setAnchorPoint(CCPointZero); labelBgSprite->setPosition(CCPointZero); labelBgSprite->setTag(Key_Add); CCMenu* pMenu = CCMenu::create(labelBgSprite, NULL); pMenu->setPosition(ccp(300,0)); pMenu->setTag(Key_Add); this->addChild(pMenu); //时间标签. CCLabelTTF *timeLabel = CCLabelTTF::create("", "Arial", 20); ccColor3B color = ccc3(95, 46, 33); char strTime[32]; sprintf(strTime,"%d:%d%d",addRiceTime/60,addRiceTime%60/10,addRiceTime%60%10); timeLabel->setColor(color); timeLabel->setString(strTime); timeLabel->setTag(Key_Time); timeLabel->setPosition(ccp(pMenu->getPositionX()+40, pMenu->getPositionY()+20)); this->addChild(timeLabel); //饭的背景 CCSprite *riceBgSprite = GameShare_Texture::sharedTexture()->GetSpriteByCCRect(akoomenu_image, CCRect(1, 1570, 278, 30)); riceBgSprite->setAnchorPoint(CCPointZero); riceBgSprite->setPosition(ccp(0,5)); this->addChild(riceBgSprite); this->schedule(schedule_selector(GameSprite_Rice::timeUpdate), 1.0); return true; }
bool MCSkillLayer::init() { if (MCBaseInfoLayer::init()) { CCSize winSize = CCDirectorGetWindowsSize(); float contentScaleFactor = CC_CONTENT_SCALE_FACTOR(); CCMenu *menu; CCLabelTTF *label; CCMenuItem *menuItem; float fontSize = 24.0f / contentScaleFactor; float offsetXLeft = 200 / contentScaleFactor; content_.push_back(JsonBox::Value("name")); content_.push_back(JsonBox::Value("releaseTime")); content_.push_back(JsonBox::Value("activeTime")); content_.push_back(JsonBox::Value("coldTime")); content_.push_back(JsonBox::Value("consume")); content_.push_back(JsonBox::Value("requiredProficiency")); content_.push_back(JsonBox::Value("revise")); content_.push_back(JsonBox::Value("count")); content_.push_back(JsonBox::Value("effect")); selectedSkill_ = NULL; /* 技能种类 */ menu = CCMenu::create(); label = CCLabelTTF::create("剑", "", fontSize); menuItem = CCMenuItemLabel::create(label, this, menu_selector(MCSkillLayer::selectSkillType)); menuItem->setTag(MCSwordSkill); menu->addChild(menuItem); label = CCLabelTTF::create("锤", "", fontSize); menuItem = CCMenuItemLabel::create(label, this, menu_selector(MCSkillLayer::selectSkillType)); menuItem->setTag(MCHammerSkill); menu->addChild(menuItem); label = CCLabelTTF::create("斧", "", fontSize); menuItem = CCMenuItemLabel::create(label, this, menu_selector(MCSkillLayer::selectSkillType)); menuItem->setTag(MCAxeSkill); menu->addChild(menuItem); label = CCLabelTTF::create("枪", "", fontSize); menuItem = CCMenuItemLabel::create(label, this, menu_selector(MCSkillLayer::selectSkillType)); menuItem->setTag(MCSpearSkill); menu->addChild(menuItem); label = CCLabelTTF::create("弓", "", fontSize); menuItem = CCMenuItemLabel::create(label, this, menu_selector(MCSkillLayer::selectSkillType)); menuItem->setTag(MCBowSkill); menu->addChild(menuItem); menu->alignItemsVerticallyWithPadding(4); addChild(menu); menu->setAnchorPoint(ccp(0, 0.5)); menu->setPosition(ccp(offsetXLeft, winSize.height / 2)); /* 技能表格 */ tableViewSize_ = CCSizeMake(180 / contentScaleFactor, 320 / contentScaleFactor); tableView_ = CCTableView::create(this, tableViewSize_); addChild(tableView_); tableView_->setDirection(kCCScrollViewDirectionVertical); tableView_->setDelegate(this); tableView_->setVerticalFillOrder(kCCTableViewFillTopDown); tableView_->setAnchorPoint(ccp(0, 0.5)); tableView_->setPosition(ccp(menu->getPositionX() + menuItem->getContentSize().width, (winSize.height - tableViewSize_.height) / 2)); contentTableView_ = CCTableView::create(this, tableViewSize_); addChild(contentTableView_); contentTableView_->setDirection(kCCScrollViewDirectionVertical); contentTableView_->setDelegate(this); contentTableView_->setVerticalFillOrder(kCCTableViewFillTopDown); contentTableView_->setAnchorPoint(ccp(0, 0.5)); contentTableView_->setPosition(ccp(tableView_->getPositionX() + tableViewSize_.width, (winSize.height - tableViewSize_.height) / 2)); contentTableView_->setVisible(false); icon_ = CCSprite::create(); addChild(icon_); icon_->setAnchorPoint(ccp(1, 1)); icon_->setPosition(ccp(winSize.width - 64.0f / contentScaleFactor, winSize.height - 64.0f / contentScaleFactor)); proficiency_ = CCLabelTTF::create("熟练度", "", fontSize); addChild(proficiency_); proficiency_->setAnchorPoint(ccp(1, 0)); proficiency_->setPosition(ccp(winSize.width - 64.0f / contentScaleFactor, 64.0f / contentScaleFactor)); proficiency_->setVisible(false); selectedCell_ = NULL; selectedSkill_ = NULL; return true; } return false; }
// on "init" you need to initialize your instance bool TestAircraft::init() { if ( !CCLayer::init() ) { return false; } // ------------ // init input manager // --------------- InputManager* input = InputManager::sharedInstance(); CCDirector::sharedDirector()->getKeypadDispatcher()->addDelegate(input); // ------------- // init physics // ----------- PhysicsManager::sharedInstance()->enableDebugDraw(true); GB2ShapeCache::sharedGB2ShapeCache()->addShapesWithFile("png/physics.plist"); // step schedule(schedule_selector(TestAircraft::stepForPhysicsManager)); // ----------------- // Init Audio // ------------ SimpleAudioEngine::sharedEngine()->preloadEffect("wav/exploStd.wav"); // ------------ // Hero Aircraft // ----------- Aircraft* hero = Aircraft::createHeroAircraft(); addChild(hero); CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); hero->setPosition(screenSize.width/2, screenSize.height/2); GameController::sharedInstance()->setPlayerAircraft(hero); // ------------ // create menu // ------------- CCMenu* menu = CCMenu::create(); // straight menu item { CCMenuItemFont* menuItem = CCMenuItemFont::create("straight", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } // omni { CCMenuItemFont* menuItem = CCMenuItemFont::create("omni", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } // ray gun { CCMenuItemFont* menuItem = CCMenuItemFont::create("ray gun", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } // tank { CCMenuItemFont* menuItem = CCMenuItemFont::create("tank", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } // boss00 { CCMenuItemFont* menuItem = CCMenuItemFont::create("boss00", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } // boss01 { CCMenuItemFont* menuItem = CCMenuItemFont::create("boss01", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } // hero { CCMenuItemFont* menuItem = CCMenuItemFont::create("hero", this, menu_selector(TestAircraft::menuItemCallback)); menu->addChild(menuItem); } menu->alignItemsVertically(); addChild(menu); menu->setPositionX(menu->getPositionX() + 200); return true; }