//----------------------------------------------------------------------------- //todo 预载入资源,实现StartScene后将其删除 void CGameScene::preloadResources() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fishingjoy_resource.plist"); //以下代码创建了两个不同的动画帧序列,使用时获取动画可以这么做:CCAnimation* animation = CCAnimationCache::sharedAnimationCache()->animationByName(const char* name); int frameCount = STATIC_DATA_INT("fish_frame_count"); for (int type = k_Fish_Type_Red; type < k_Fish_Type_Count; type++) { //以下代码会创建animation失败 // CCAnimation* fishAnimation = CCAnimation::create(); // for (int i = 0; i < frameCount; i++) // { // fishAnimation->addSpriteFrameWithFileName( // CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i)->getCString()); // } CCArray* spriteFramesArray = CCArray::createWithCapacity(frameCount); for (int i = 0; i < frameCount; i++) { CCString* fileName = CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName->getCString()); spriteFramesArray->addObject(spriteFrame); } CCAnimation* fishAnimation = CCAnimation::createWithSpriteFrames(spriteFramesArray); fishAnimation->setDelayPerUnit(STATIC_DATA_FLOAT("fish_frame_delay")); CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"),type); CCAnimationCache::sharedAnimationCache()->addAnimation(fishAnimation, animationName->getCString()); } }
void PanelLayer::removeAndPlace(int tag, const char* propName) { menuProp->removeChildByTag(tag, true); if (tag == LEFT) { propLeft = CCMenuItemImage::create( propName, STATIC_DATA_STRING("prop_nothing"), this, menu_selector(PanelLayer::useLeftPro)); propLeft->setTag(tag); menuProp->addChild(propLeft); leftPlaced = false; } else { propRight = CCMenuItemImage::create( propName, STATIC_DATA_STRING("prop_nothing"), this, menu_selector(PanelLayer::useRightPro)); propRight->setTag(tag); menuProp->addChild(propRight); rightPlaced = false; } CCSize proSize = propLeft->getContentSize(); menuProp->setPosition(CCPointMake(proSize.width * 3 / 2, proSize.height * 0.618)); menuProp->alignItemsHorizontallyWithPadding(proSize.width / 3); }
void PopWindowsLayer::showGetEquiment(Equipment* GetEquipment ) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* pBg1 = CCSprite::create(STATIC_DATA_STRING("pop_window_equipment")); pBg1->setPosition(CCPointMake(winSize.width/2,winSize.height*3/4)); this->addChild(pBg1); int equipment = 0; if(GetEquipment->getWeapon()) equipment = 1; if(GetEquipment->getBase()) equipment = 2; if(GetEquipment->getPlate()) equipment = 3; std::string name1 = "pop_window_equipment_property_"; char e = (char) (equipment+48); name1.append(&e); CCSprite* pBg2 = CCSprite::create(STATIC_DATA_STRING(name1)); pBg2->setPosition(CCPointMake(winSize.width*2/5,winSize.height/2)); this->addChild(pBg2); std::string name2 = "pop_window_equipment_graph_"; name2.append(&e); CCSprite* pBg3 = CCSprite::create(STATIC_DATA_STRING(name2)); pBg3->setPosition(CCPointMake(winSize.width*2/3,winSize.height/2)); this->addChild(pBg3); CCSprite* pBg4 = CCSprite::create(STATIC_DATA_STRING("pop_window_banner")); pBg4->setPosition(CCPointMake(winSize.width*2/3,winSize.height/4)); this->addChild(pBg4); }
void PopWindowsLayer::showUpGrade(int level) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* pBg1 = CCSprite::create(STATIC_DATA_STRING("pop_window_upgrade")); pBg1->setPosition(CCPointMake(winSize.width/2,winSize.height*3/4)); this->addChild(pBg1); std::string name = "pop_window_upgrade_property_"; char* e = new char[4]; int size = 0; while(level >0) { e[size] = 48 + level%10; level = level/10; size++; } e[size] = 0; size --; while(size>=0) { name.append(e+size); e[size]=0; size--; } //std::cout<<e<<std::endl; // std::cout<<name<<std::endl; CCSprite* pBg2 = CCSprite::create(STATIC_DATA_STRING(name)); pBg2->setPosition(CCPointMake(winSize.width*2/5,winSize.height/2)); this->addChild(pBg2); CCSprite* pBg3 = CCSprite::create(STATIC_DATA_STRING("pop_window_upgrade_graph")); pBg3->setPosition(CCPointMake(winSize.width*2/3,winSize.height/2)); this->addChild(pBg3); }
void PopWindowsLayer::drawConfirmButton() { CCMenuItemImage* item = CCMenuItemImage::create( STATIC_DATA_STRING("pop_window_button_normal"), STATIC_DATA_STRING("pop_window_button_click"), this, this->confirmButtonHandler ); item->setPosition(CCPointMake(WIN_SIZE.width/2,WIN_SIZE.height/7)); this->menu->addChild(item); }
void PopWindowsLayer::createSureAndButtons() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenuItemImage* pBackItem = CCMenuItemImage::create( STATIC_DATA_STRING("pop_window_button_normal"), STATIC_DATA_STRING("pop_window_button_click"), this, menu_selector(PopWindowsLayer::removeFromParentCallback) ); CCMenu* menu = CCMenu::create(pBackItem,NULL); menu->setPosition(CCPointMake(winSize.width/2,winSize.height/7)); this->addChild(menu); }
void PopWindowsLayer::showEvolve() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* pBg1 = CCSprite::create(STATIC_DATA_STRING("pop_window_evolve")); pBg1->setPosition(CCPointMake(winSize.width/2,winSize.height*3/4)); this->addChild(pBg1); CCSprite* pBg2 = CCSprite::create(STATIC_DATA_STRING("pop_window_evolve_property")); pBg2->setPosition(CCPointMake(winSize.width*2/5,winSize.height/2)); this->addChild(pBg2); CCSprite* pBg3 = CCSprite::create(STATIC_DATA_STRING("pop_window_evolve_graph")); pBg3->setPosition(CCPointMake(winSize.width*2/3,winSize.height/2)); this->addChild(pBg3); }
void RegisterLayer::drawBack() { CCMenuItemImage* pBackItem = CCMenuItemImage::create( STATIC_DATA_STRING("Log_Register_Register_normal-back"), STATIC_DATA_STRING("Log_Register_Register_click-back"), this, menu_selector(RegisterLayer::clickBack) ); CCMenu* menu = CCMenu::create(pBackItem,NULL); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint pos = CCPointMake(winSize.width*104/300,winSize.height*11/50); menu->setPosition(pos); this->addChild(menu); }
bool FishingNet::init() { _fishingNetSprite = CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("fishing_net")); this->addChild(_fishingNetSprite); return true; }
void RegisterLayer::drawUsernameRight() { CCMenuItemImage* pBackItem = CCMenuItemImage::create( STATIC_DATA_STRING("Log_Register_Register_inputbox-normal"), STATIC_DATA_STRING("Log_Register_Register_inputbox-click"), this, menu_selector(RegisterLayer::usernameTextFieldPressed) ); CCMenu* menu = CCMenu::create(pBackItem,NULL); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint pos = CCPointMake(winSize.width*18/30,winSize.height*35/50); menu->setPosition(pos); this->addChild(menu); }
void PanelLayer::pause(cocos2d::CCObject* pSender) { PersonalAudioEngine::sharedEngine()->playEffect(STATIC_DATA_STRING("click_button")); this->getChildByTag(MENUTAG)->setVisible(false); GameScene* gameScene = (GameScene*)this->getParent(); gameScene->pause(); }
void LogIntoLayer::drawLogInto() { CCMenuItemImage* pBackItem = CCMenuItemImage::create( STATIC_DATA_STRING("Log_Register_Log_into_normal-longin"), STATIC_DATA_STRING("Log_Register_Log_into_click-longin"), this, menu_selector(LogIntoLayer::clickLogInto) ); CCMenu* menu = CCMenu::create(pBackItem,NULL); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint pos = CCPointMake(winSize.width*196/300,winSize.height*11/50); menu->setPosition(pos); this->addChild(menu); }
void LogIntoLayer::drawPasswordRight() { CCMenuItemImage* pBackItem = CCMenuItemImage::create( STATIC_DATA_STRING("Log_Register_Log_into_inputbox-normal"), STATIC_DATA_STRING("Log_Register_Log_into_inputbox-click"), this, menu_selector(LogIntoLayer::passwordTextFieldPressed) ); CCMenu* menu = CCMenu::create(pBackItem,NULL); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint pos = CCPointMake(winSize.width*283/500,winSize.height*22/50); menu->setPosition(pos); this->addChild(menu); }
void PopWindowsLayer::showWindows() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* pBg = CCSprite::create(STATIC_DATA_STRING("pop_window_window")); pBg->setPosition(CCPointMake(winSize.width/2,winSize.height/2)); this->addChild(pBg); }
void PopWindowsLayer::drawDescriptoin() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* pBg = CCSprite::create(CCString::createWithFormat(STATIC_DATA_STRING("pop_window_description_image_format"),(int)this->windowsType,(int)this->itemType)->getCString()); pBg->setPosition(CCPointMake(winSize.width*2/5,winSize.height/2)); this->addChild(pBg); }
void LogIntoLayer::drawRegisterNewUser() { CCMenuItemImage* pBackItem = CCMenuItemImage::create( STATIC_DATA_STRING("Log_Register_Log_into_newaccount-normal"), STATIC_DATA_STRING("Log_Register_Log_into_newaccount-click"), this, menu_selector(LogIntoLayer::clickRegisterNewUser) ); CCMenu* menu = CCMenu::create(pBackItem,NULL); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint pos = CCPointMake(winSize.width*368/500,winSize.height*505/600); menu->setPosition(pos); this->addChild(menu); }
bool Bullet::init() { _bulletSprite = CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("bullet")); _bulletSprite->setAnchorPoint(CCPointMake(0.5,1.0)); this->addChild(_bulletSprite); return true; }
void LogIntoLayer::drawBackground() { CCSprite* pBg = CCSprite::create(STATIC_DATA_STRING( "Log_Register_Register_window")); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); pBg->setPosition(CCPointMake(winSize.width/2,winSize.height/2)); this->addChild(pBg); }
void RegisterLayer::drawUsernameLeft() { CCSprite* pBg = CCSprite::create(STATIC_DATA_STRING( "Log_Register_Register_account")); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); pBg->setPosition(CCPointMake(winSize.width*9/30,winSize.height*35/50)); this->addChild(pBg); }
void LogIntoLayer::drawPasswordLeft() { CCSprite* pBg = CCSprite::create(STATIC_DATA_STRING( "Log_Register_Log_into_password")); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); pBg->setPosition(CCPointMake(winSize.width*105/400,winSize.height*224/500)); this->addChild(pBg); }
void GameScene::pause() { PersonalAudioEngine::sharedEngine()->pauseBackgroundMusic(); PersonalAudioEngine::sharedEngine()->playEffect(STATIC_DATA_STRING("sound_button")); this->operateAllSchedulerAndActions(this,k_Operate_Pause ); _touchLayer->setTouchEnabled(false); //close touchlayer this->addChild(_menuLayer); }
//todo 预载入资源,实现StartScene后将其删除 void GameScene::preloadResources() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fishingjoy_resource.plist"); int frameCount = STATIC_DATA_INT("fish_frame_count"); for (int type = k_Fish_Type_Red; type < k_Fish_Type_Count; type++) { CCArray* spriteFrames = CCArray::createWithCapacity(frameCount); for(int i = 0;i < frameCount;i++){ CCString* filename = CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"),type,i); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString()); spriteFrames->addObject(spriteFrame); } CCAnimation* fishAnimation = CCAnimation::createWithSpriteFrames(spriteFrames); fishAnimation->setDelayPerUnit(STATIC_DATA_FLOAT("fish_frame_delay")); CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), type); CCAnimationCache::sharedAnimationCache()->addAnimation(fishAnimation, animationName->getCString()); } }
void PanelLayer::useRightPro(cocos2d::CCObject* pSender) { this->getRightProp()->playEffect(); removeAndPlace(RIGHT, STATIC_DATA_STRING("prop_nothing")); Prop* prop = Prop::create(No_Prop); this->setRightProp(prop); rightPlaced = false; // TO-DO // Example: }
void PanelLayer::useLeftPro(cocos2d::CCObject* pSender) { this->getLeftProp()->playEffect(); removeAndPlace(LEFT, STATIC_DATA_STRING("prop_nothing")); Prop* prop = Prop::create(No_Prop); this->setLeftProp(prop); leftPlaced = false; // TO-DO // Example: add the ap and so on }
bool Fish::init(FishType type) { _type = type; CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), _type); CCAnimation* fishAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(animationName->getCString()); CCAnimate* fishAnimate = CCAnimate::create(fishAnimation); fishAnimate->setTag(k_Action_Animate); _fishSprite = CCSprite::create(); this->addChild(_fishSprite); _fishSprite->runAction(CCRepeatForever::create(fishAnimate)); return true; }
bool BackgroundLayer::init() { if (CCLayer::init()) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite *background = CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("background")); background->setPosition(CCPointMake(winSize.width*0.5f, winSize.height*0.5f)); this->addChild(background); return true; } return false; }
bool Cannon::init(CannonType type){ _cannonSprites = CCArray::createWithCapacity(k_Cannon_Type_Count); _cannonSprites->retain(); CCPoint anchorPoint = CCPointMake(0.5, 0.26); for (int i = k_Cannon_Type_1; i < k_Cannon_Type_Count; ++i){ CCString* fileName = CCString::createWithFormat(STATIC_DATA_STRING("cannon_level_name_format"), i + 1); CCSprite* cannonSprite = CCSprite::createWithSpriteFrameName(fileName->getCString()); cannonSprite->setAnchorPoint(anchorPoint); _cannonSprites->addObject(cannonSprite); } this->setType(type); return true; }
//----------------------------------------------------------------------------- bool CFish::init(EFishType type) { //CCAnimation只是用于存放动画,真正让动画播放起来的是动作类CCAnimate //CCAnimate只能由CCSprite及其子类播放 m_type = type; CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), m_type); CCAnimation* fishAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(animationName->getCString()); CCAnimate* fishAnimate = CCAnimate::create(fishAnimation); fishAnimate->setTag(k_Action_Animate); m_fishSprite = CCSprite::create(); this->addChild(m_fishSprite); m_fishSprite->runAction(CCRepeatForever::create(fishAnimate)); return true; }
void PanelLayer::placeProp(Prop* prop) { CCString* spriteName = CCString::createWithFormat(STATIC_DATA_STRING("prop_format"),prop->getPropType()); if (!leftPlaced) { this->setLeftProp(prop); removeAndPlace(LEFT, spriteName->getCString()); leftPlaced = true; } else if (!rightPlaced) { this->setRightProp(prop); removeAndPlace(RIGHT, spriteName->getCString()); rightPlaced = true; } return; }
void Army::onEnter() { LayerWithDialog::onEnter(); this->setTouchEnabled(true); char url[255]; std::string server = STATIC_DATA_STRING("server"); sprintf(url, "%sarms/infoApi&SID=%s", server.c_str(), Load::sharedSessionId.c_str()); request->setUrl(url); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, httpresponse_selector(Army::onInfoRequestCompleted)); request->setTag("arms"); cocos2d::extension::CCHttpClient::getInstance()->send(request); request->release(); }