void CGameView::onEnter() { Layer::onEnter(); //---------------------------------------------------- //FIXME count = 0; Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(CGameView::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2, origin.y + closeItem->getContentSize().height / 2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); //---------------------------------------------------- log("CGameView OnEnter..."); auto lisnter = EventListenerTouchOneByOne::create(); lisnter->onTouchBegan = CC_CALLBACK_2(CGameView::onTouchBegan, this); lisnter->onTouchEnded = CC_CALLBACK_2(CGameView::onTouchEnded, this); lisnter->onTouchMoved = CC_CALLBACK_2(CGameView::onTouchMove, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(lisnter, this); //-------------------------------------------------------------------- m_pPath = new CPath(); m_pDrawNode = DrawNode::create(); m_pSp = CMySprite::create(); m_pPlayer = CGamePlayer::create(); m_pShowArea = CShowArea::create(); m_pGameLogic = CGameLogic::create(); //------------------------------------ m_pSp->setPath(m_pPath); m_pSp->setPlayer(m_pPlayer); m_pSp->setShowArea(m_pShowArea); m_pSp->setVisible(false); m_pShowArea->setPath(m_pPath); m_pShowArea->setPosition(origin); m_pPlayer->m_refSp = m_pSp; m_pPlayer->setVisible(false); m_pGameLogic->m_refPath = m_pPath; m_pGameLogic->m_refPlayer = m_pPlayer; m_pGameLogic->m_refShowArea = m_pShowArea; m_pGameLogic->m_refSp = m_pSp; m_pGameLogic->setAnchorPoint(Vec2::ZERO); //---------------------------- addChild(m_pShowArea); addChild(m_pSp); addChild(m_pDrawNode); addChild(m_pGameLogic); addChild(m_pPlayer); //------------------------------------ m_oAllRander.push_back(m_pSp); m_oAllRander.push_back(m_pShowArea); m_oAllRander.push_back(m_pPath); m_oAllRander.push_back(m_pPlayer); //---------------------------------------- m_oAllRunner.push_back(m_pSp); m_oAllRunner.push_back(m_pPlayer); //------------------------------------------ CEventDispatcher::getInstrance()->regsiterEvent(EVENT_WIN, this); CEventDispatcher::getInstrance()->regsiterEvent(EVENT_TIMEOUT, this); CEventDispatcher::getInstrance()->regsiterEvent(EVENT_PLAYERDIE, this); setState(STATE_INIT); schedule(schedule_selector(CGameView::run)); }
void MainMenuScene::dataLoaded(float percent) { switch (loadingCount) { case ACTION_RUN: { CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("animations/ChenXiaoGeRunning.ExportJson",this, schedule_selector(MainMenuScene::dataLoaded)); } break; default: { CCScene * newscene = CCScene::create(); GameScene* gameScene = GameScene::newGameScene(); CCTransitionFade* gameSceneTransition = CCTransitionFade::create(0.5, gameScene, ccWHITE); CCDirector::sharedDirector()->replaceScene(gameSceneTransition); } break; } loadingCount++; }
////////////////////////////////////////////////////////////////////////////////////////// // Creates the context of the game. Adds background, the score text onto the // game. // Also setups the game scheduling and other handlers. ////////////////////////////////////////////////////////////////////////////////////////// bool GameScene::init() { if (!CCLayer::init()) { return false; } windowSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // setup game scheduling/handling/other attributes _score = 0; _modifier = 1; _lastPairMatched = false; _pairsMatched = 0; this->_gameOver = false; this->_lastElapsedTime = GameUtils::getCurrentTime(); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect( "bubble_pop.mp3"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect( "bubble_pop_2.mp3"); this->setTouchEnabled(true); // add background _background = CCSprite::create(BackgroundImage); _background->setPosition( ccp(windowSize.width / 2 + origin.x, windowSize.height / 2 + origin.y)); this->addChild(_background, ZIndexBackground); // add score label char scoreText[25]; sprintf(scoreText, " %d", _score); _scoreLabel = CCLabelTTF::create(scoreText, "Marker Felt.ttf", LABEL_FONT_SIZE); _scoreLabel->setColor(GameUtils::getRandomColor3B()); _scoreLabel->setAnchorPoint(ccp(0, 0)); _scoreLabel->cocos2d::CCNode::setPosition( ccp(LABEL_MARGIN, windowSize.height - topScreenAdjust())); this->addChild(_scoreLabel, ZIndexGameTextLabels); //add modifier label char modifierText[15]; sprintf(modifierText, "%dx", _modifier); _modifierLabel = CCLabelTTF::create(modifierText, "Marker Felt.ttf", LABEL_FONT_SIZE); _modifierLabel->setColor(GameUtils::getRandomColor3B()); _modifierLabel->setAnchorPoint(ccp(0, 0)); _modifierLabel->cocos2d::CCNode::setPosition(ccp(windowSize.width - _modifierLabel->getContentSize().width - (LABEL_MARGIN * 1.75), windowSize.height - topScreenAdjust())); this->addChild(_modifierLabel, ZIndexGameTextLabels); // add go image _goTextImage = CCMenuItemImage::create("text_go.png", "text_go.png", this, NULL); _goTextImage->setPosition(ccp(windowSize.width / 2, windowSize.height / 2)); this->addChild(_goTextImage, ZIndexGoImage); // add initial balls _ballArray = *new std::vector<Ball*>(); for (int i = 0; i < STARTING_BALLS / 2; i++) { createNewBalls(); } this->schedule(schedule_selector(GameScene::GameUpdate), 0.01); return true; }
void InGamePowers::OnStartRecharge(int theID) { // Clear old stuff if(theID == 0) { mGameScene->OnTryToShoot(); mLoad_1_StringStream.str(""); mLoad_1_StringStream.clear(); mButton_1_Load->setString("0%"); mButton_1_Load->setVisible(true); mButton_1_Icon->setColor(ccGRAY); // Run the magic CCProgressFromTo* aAction = CCProgressFromTo::create(mPowerCoolDown_1, 0, 100); mButton_1_Progress->runAction(aAction); // Start the progress bar stuff schedule(schedule_selector(InGamePowers::OnUpdateProgress_1)); } else if(theID == 1) { mGameScene->mMasterTroll_Attack-=mPowerCost_2; OnGhoustDwarfs(); mLoad_2_StringStream.str(""); mLoad_2_StringStream.clear(); mButton_2_Load->setString("0%"); mButton_2_Load->setVisible(true); mButton_2_Icon->setColor(ccGRAY); // Run the magic CCProgressFromTo* aAction = CCProgressFromTo::create(mPowerCoolDown_2, 0, 100); mButton_2_Progress->runAction(aAction); // Start the progress bar stuff schedule(schedule_selector(InGamePowers::OnUpdateProgress_2)); } else if(theID == 2) { mGameScene->mMasterTroll_Attack-=mPowerCost_3; mGameScene->StartDwarfFreeze_All(); mLoad_3_StringStream.str(""); mLoad_3_StringStream.clear(); mButton_3_Load->setString("0%"); mButton_3_Load->setVisible(true); mButton_3_Icon->setColor(ccGRAY); // Run the magic CCProgressFromTo* aAction = CCProgressFromTo::create(mPowerCoolDown_3, 0, 100); mButton_3_Progress->runAction(aAction); // Start the progress bar stuff schedule(schedule_selector(InGamePowers::OnUpdateProgress_3)); } mGameScene->UpdateBattleLabel(); }
//------------------------------------------------------------------ // // SchedulerUpdateFromCustom // //------------------------------------------------------------------ void SchedulerUpdateFromCustom::onEnter() { SchedulerTestLayer::onEnter(); schedule(schedule_selector(SchedulerUpdateFromCustom::schedUpdate), 2.0f); }
void PlayScene::update(float delta) { if (sharedDelegate()->CheckRecv()) { unschedule(schedule_selector(PlayScene::update)); } }
bool CMainMenuScene::init() { if(!CCLayer::init()) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object //New game menu item if((!CAudioManager::instance()->isBGMusicPlaying()) && CAudioManager::instance()->GetSound()==SOUND_BG_EFF) CAudioManager::instance()->playBGMusic(SOUND_BACKGROUND_MAIN, true); //create menu m_pMenu = CCMenu::create(NULL, NULL); m_pMenu->setPosition( CCPointZero ); //Button play { CCMenuItemImage *pPlayButton = CCMenuItemImage::create( "MainMenuScene\\play1.png", "MainMenuScene\\play2.png", this, menu_selector(CMainMenuScene::menuNewgameCallback)); pPlayButton->setPosition(LOCATION_BUTTON_PLAY); m_pMenu->addChild(pPlayButton); } ////Button Exit { CCMenuItemImage *pExitButton = CCMenuItemImage::create( "MainMenuScene\\exit1.png", "MainMenuScene\\exit2.png", this, menu_selector(CMainMenuScene::menuCloseCallback)); pExitButton->setPosition(LOCATION_BUTTON_EXIT); m_pMenu->addChild(pExitButton); } //BUtton About { CCMenuItemImage *pAboutButton = CCMenuItemImage::create( "MainMenuScene\\about1.png", "MainMenuScene\\about2.png", this, menu_selector(CMainMenuScene::menuAboutCallback)); pAboutButton->setPosition(LOCATION_BUTTON_ABOUT); m_pMenu->addChild(pAboutButton); } //Button Option { CCMenuItemImage *pOptionsButton = CCMenuItemImage::create( "MainMenuScene\\option1.png", "MainMenuScene\\option2.png", this, menu_selector(CMainMenuScene::menuOptionsCallback)); pOptionsButton->setPosition(LOCATION_BUTTON_OPTION); m_pMenu->addChild(pOptionsButton); } //Button Help { CCMenuItemImage *pHelpButton = CCMenuItemImage::create( "MainMenuScene\\help1.png", "MainMenuScene\\help2.png", this, menu_selector(CMainMenuScene::menuHelpCallback)); pHelpButton->setPosition(LOCATION_BUTTON_HELP); m_pMenu->addChild(pHelpButton); } this->addChild(m_pMenu, 1); //Background CCSprite* pSprite = CCSprite::create("MainMenuScene\\protectlane.png"); pSprite->setPosition( ccp(size.width/2, size.height/2) ); this->addChild(pSprite, 0); //Animation Fire CMySprite* pAnimFire=new CMySprite("Tower\\tower.sprite"); pAnimFire->setPosition(LOCATION_ANIM_FIRE); pAnimFire->setScale(1.5f); this->addChild(pAnimFire); pAnimFire->PlayAnimation(FIRE_TOWER, 0.4f, true, false); /************************************************************************/ /* Pop up Menu */ /************************************************************************/ CCMenuItemImage *pYesItem = CCMenuItemImage::create( "Button\\yes-down.png", "Button\\yes-up.png", this, menu_selector(CMainMenuScene::PopupYesCallback)); //pYesItem->setPosition(size.width/2.0f + 100.0f, size.height/2.0f); pYesItem->setPosition(220.0f, 0.0f); CCMenuItemImage *pNoItem = CCMenuItemImage::create( "Button\\no-down.png", "Button\\no-up.png", this, menu_selector(CMainMenuScene::PopupNoCallback)); //pNoItem->setPosition(size.width/2.0f + 150.0f, size.height/2.0f); pNoItem->setPosition(380.0f, 0.0f); m_pBlurLayer = CCLayerColor::create(); m_pBlurLayer->setOpacityModifyRGB(true); m_pBlurLayer->setColor(ccc3(0,0,0)); m_pBlurLayer->setOpacity(150); this->addChild(m_pBlurLayer, ZORDER_GAMEPLAY_COLOR_LAYER, TAG_GAMEPLAY_COLOR_LAYER); //set position of Popup pPopupBackground = CCSprite::create("Button\\popup1.png"); pPopupBackground->setPosition(ccp( size.width/2, size.height/2 )); this->addChild(pPopupBackground,ZORDER_GAMEPLAY_COLOR_LAYER + 1, TAG_GAMEPLAY_COLOR_LAYER + 1); m_pPopupMenu = CCMenu::create(pYesItem, NULL); m_pPopupMenu->addChild(pNoItem); this->addChild(m_pPopupMenu,ZORDER_GAMEPLAY_COLOR_LAYER + 1, TAG_GAMEPLAY_COLOR_LAYER + 1); EnablePopupMenu(false); schedule(schedule_selector(CMainMenuScene::update)); CCDirector::sharedDirector()->getTouchDispatcher()->removeAllDelegates(); setTouchEnabled(false); return true; }
void CATouchController::touchMoved() { CC_RETURN_IF(ccpDistance(m_tFirstPoint, m_pTouch->getLocation()) < _px(32)); m_tFirstPoint = CCPointZero; if (!m_vTouchMovedsViewCache.empty()) { bool isScheduledPassing = CAScheduler::isScheduled(schedule_selector(CATouchController::passingTouchesViews), this); CAScheduler::unschedule(schedule_selector(CATouchController::passingTouchesViews), this); while (!m_vTouchMovedsViewCache.empty()) { CAResponder* responder = m_vTouchMovedsViewCache.back(); CCPoint pointOffSet = CCPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } pointOffSet.x = fabsf(pointOffSet.x); pointOffSet.y = fabsf(pointOffSet.y); do { CC_BREAK_IF(!responder->isTouchMovedListenHorizontal() && pointOffSet.x >= pointOffSet.y); CC_BREAK_IF(!responder->isTouchMovedListenVertical() && pointOffSet.x < pointOffSet.y); m_vTouchMovedsView.pushBack(m_vTouchMovedsViewCache.back()); } while (0); m_vTouchMovedsViewCache.popBack(); } CAVector<CAResponder * > tTouchesViews = m_vTouchesViews; if (!m_vTouchMovedsView.empty()) { if (!isScheduledPassing) { CAVector<CAResponder*>::iterator itr; // for (itr = m_vTouchMovedsView.begin(); itr != m_vTouchMovedsView.end(); itr++) { m_vTouchesViews.eraseObject(*itr, true); } // for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { (*itr)->ccTouchCancelled(m_pTouch, m_pEvent); } } { m_vTouchesViews.clear(); for (int i=0; i<m_vTouchMovedsView.size(); i++) { CAResponder* responder = m_vTouchMovedsView.at(i); CCPoint pointOffSet = CCPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } if (responder->isTouchMovedListenHorizontal() && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y)) { CC_CONTINUE_IF(responder->isSlidingMinX() && pointOffSet.x > 0); CC_CONTINUE_IF(responder->isSlidingMaxX() && pointOffSet.x < 0); } if (responder->isTouchMovedListenVertical() && fabsf(pointOffSet.x) < fabsf(pointOffSet.y)) { CC_CONTINUE_IF(responder->isSlidingMinY() && pointOffSet.y > 0); CC_CONTINUE_IF(responder->isSlidingMaxY() && pointOffSet.y < 0); } m_vTouchesViews.pushBack(responder); if (tTouchesViews.contains(responder)==false) { responder->ccTouchBegan(m_pTouch, m_pEvent); } break; } if (m_vTouchesViews.empty()) { m_vTouchesViews.pushBack(m_vTouchMovedsView.front()); if (tTouchesViews.contains(m_vTouchesViews.back())==false) { m_vTouchesViews.back()->ccTouchBegan(m_pTouch, m_pEvent);// } } } } } CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder()); bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint); if (!isContainsFirstPoint && view) { view->ccTouchMoved(m_pTouch, m_pEvent); } CAVector<CAResponder*>::iterator itr; for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { (*itr)->ccTouchMoved(m_pTouch, m_pEvent); } }
bool GamePlayScene::init() { if (!LayerColor::initWithColor(Color4B(0, 255, 255, 255))) { return false; } this->setKeypadEnabled(true); _holdBack = Sprite::create("commons/images/holdback.png"); _holdBack->setPosition(Vec2(240, 400)); this->addChild(_holdBack, 0); _slideBack = Sprite::create("commons/images/slideback.png"); _slideBack->setAnchorPoint(Vec2(0.5, 0.0)); _slideBack->setPosition(Vec2(240, 0)); this->addChild(_slideBack, 1); _stageButton = MenuItemImage::create( "playscene/images/stage.png", "playscene/images/stageclicked.png", CC_CALLBACK_1(GamePlayScene::menuCloseCallback, this)); _stageButton->setAnchorPoint(Vec2(0.5, 0.5)); _stageButton->setPosition(Vec2(-190, 360)); _stageButton->setTag(1); _homeButton = MenuItemImage::create( "playscene/images/home.png", "playscene/images/homeclicked.png", CC_CALLBACK_1(GamePlayScene::menuCloseCallback, this)); _homeButton->setAnchorPoint(Vec2(0.5, 0.5)); _homeButton->setPosition(Vec2(-130, 360)); _homeButton->setTag(2); _muteButton = MenuItemImage::create( "playscene/images/sound.png", "playscene/images/sound.png", CC_CALLBACK_1(GamePlayScene::menuCloseCallback, this)); _muteButton->setAnchorPoint(Vec2(0.5, 0.5)); _muteButton->setPosition(Vec2(200, 360)); _muteButton->setTag(3); _resetButton = MenuItemImage::create( "playscene/images/return.png", "playscene/images/returnclicked.png", CC_CALLBACK_1(GamePlayScene::menuCloseCallback, this)); _resetButton->setAnchorPoint(Vec2(0.5, 0.5)); _resetButton->setPosition(Vec2(0, -360)); _resetButton->setTag(4); auto menu = Menu::create(_stageButton, _homeButton, _muteButton, _resetButton,NULL); menu->setPosition(Vec2(240, 400)); this->addChild(menu, 3); layer_top = MapLayer::create(); layer_top->setPosition(Vec2(40, 200)); layer_top->setContentSize(Size(400, 400)); layer_top->retain(); this->addChild(layer_top, 2); this->schedule(schedule_selector(GamePlayScene::backgroundSlideSchedule), 20.0f, CC_REPEAT_FOREVER, 20.0f); return true; }
void AndroidLoad::SetTime(float t) { scheduleOnce(schedule_selector(AndroidLoad::ChangeScene) , t); }
void LoadingScene::onEnterTransitionDidFinish() { CCScene::onEnterTransitionDidFinish(); this->scheduleOnce(schedule_selector(LoadingScene::loadPublicResource), 0.05); }
void LayerGame::stop() { this->unschedule(schedule_selector(LayerGame::update)); }
void LayerGame::start() { this->schedule(schedule_selector(LayerGame::update), 0.1f); this->schedule(schedule_selector(LayerGame::addBlock), 3.0f ); }
void PopupLayer::runPublishAnmi() { Util::playAudioEffect(MASHANGKAIJIANG, false); scheduleOnce(schedule_selector( PopupLayer::realRunPublishAnmi),3.0f); }
bool GameLayer::init() { if (!CCLayer::init()) { return false; } //if(self=[super init]){ this->setTouchEnabled(true); //this->initObjects(); enemies = CCArray::create(); enemies->retain(); bullets = CCArray::create(); bullets->retain(); props = CCArray::create(); props->retain(); superBullet = false; bombCount = 0; score = 0; //this->getWinsize(); winSize = CCDirector::sharedDirector()->getWinSize(); //资源加载 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("gameArts.plist"); //CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("gameArts.png"); //背景控制 backgroundSprite_1 = CCSprite::create("background_2.png"); backgroundSprite_2 = CCSprite::create("background_2.png"); //减去2px可以让两个背景块有细微重叠,会看到两个背景块中间的细缝. backgroundHeight = backgroundSprite_1->boundingBox().size.height - 3; backgroundSprite_1->setAnchorPoint(ccp(0.5f, 0)); backgroundSprite_2->setAnchorPoint(ccp(0.5f, 0)); backgroundSprite_1->setPosition(ccp(winSize.width/2, 0)); backgroundSprite_2->setPosition(ccp(winSize.width/2, backgroundHeight)); this->addChild(backgroundSprite_1, 0); this->addChild(backgroundSprite_2, 0); //this->loadBackgroundSprites(); //this->startBackgroundMoving(); this->moveBackgroundDownWithSprite(backgroundSprite_1); this->moveBackgroundDownWithSprite(backgroundSprite_2); //玩家飞机的生成和控制 playerPlane = CCSprite::create("hero_fly_1.png"); playerPlane->setPosition(ccp(winSize.width/2, 0.2*winSize.height)); this->addChild(playerPlane, 3); //this->setTouchEnabled(true); CCAction * planeAction = this->frameAnimationWithFrameName("hero_fly_%i.png", 2, 0.2f, 0); playerPlane->runAction(planeAction); CCNode::onEnter(); //子弹生成和控制 this->schedule(schedule_selector(GameLayer::shootBullet), 0.2f); //if(1)return true; //敌机生成和控制 this->schedule(schedule_selector(GameLayer::showEnemy), 0.8f); //if(1)return true; //碰撞检测 this->schedule(schedule_selector(GameLayer::checkingCollision)); bomb = CCSprite::create("bomb.png"); bomb->setAnchorPoint( ccp(0, 0)); bomb->setPosition( ccp(winSize.width*0.05, winSize.width*0.05)); this->addChild(bomb); bomb->setVisible(false); //道具生成和控制 this->schedule(schedule_selector(GameLayer::showProp), 20.0f); //分数标签 scoreLabel = CCLabelTTF::create("Score:0", "MarkerFelt-Thin", winSize.height * 0.0625); scoreLabel->setColor(ccc3(0, 0, 0)); scoreLabel->setAnchorPoint(ccp(0, 1)); scoreLabel->setPosition(ccp(0, winSize.height)); this->addChild(scoreLabel); //} return true; }
void EnemyInfoController::purgeData() { CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(EnemyInfoController::onEnterFrame), _instance); CC_SAFE_RELEASE_NULL( _instance ); _instance = NULL; }
void PlayScene::CARecvTimeout() { TextBox::Instance().Show(ui_layer_text_, false); unschedule(schedule_selector(PlayScene::update)); }
bool GameLayer::init(){ if(Layer::init()) { //get the origin point of the X-Y axis, and the visiable size of the screen Size visiableSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); this->gameStatus = GAME_STATUS_READY; this->score = 0; // Add the bird this->bird = BirdSprite::getInstance(); this->bird->createBird(); PhysicsBody *body = PhysicsBody::create(); body->addShape(PhysicsShapeCircle::create(BIRD_RADIUS)); body->setCategoryBitmask(ColliderTypeBird); body->setCollisionBitmask(ColliderTypeLand & ColliderTypePip | ColliderTypeBall); body->setContactTestBitmask(ColliderTypeLand | ColliderTypePip | ColliderTypeBall); body->setDynamic(true); body->setLinearDamping(0.0f); body->setGravityEnable(false); this->bird->setPhysicsBody(body); this->bird->setPosition(origin.x + visiableSize.width*1/3 - 5,origin.y + visiableSize.height/2 + 5); this->bird->idle(); this->addChild(this->bird); //Ball this->ball = Sprite::create("Ball.png"); PhysicsBody *ballbody = PhysicsBody::create(); ballbody->addShape(PhysicsShapeCircle::create(BIRD_RADIUS+5)); ballbody->setCategoryBitmask(ColliderTypeBall); ballbody->setCollisionBitmask(ColliderTypePip | ColliderTypeLand); ballbody->setContactTestBitmask(ColliderTypePip | ColliderTypeLand); ballbody->setDynamic(true); ballbody->setLinearDamping(0.0f); ballbody->setGravityEnable(false); ball->setPhysicsBody(ballbody); ball->setPosition(bird->getPositionX(),bird->getPositionY()+30); ball->setTag(100); addChild(ball); BallisTouch = false; //BallName // ballName = Sprite::create("BallWithHoney.png"); ballName = Sprite::create("star.png"); ballName->setPosition(ball->getPositionX(),ball->getPositionY()+40); //addChild(ballName); // Add the ground this->groundNode = Node::create(); float landHeight = BackgroundLayer::getLandHeight(); auto groundBody = PhysicsBody::create(); groundBody->addShape(PhysicsShapeBox::create(Size(288, landHeight))); groundBody->setDynamic(false); groundBody->setLinearDamping(0.0f); groundBody->setCategoryBitmask(ColliderTypeLand); groundBody->setCollisionBitmask(ColliderTypeBird | ColliderTypeBall); groundBody->setContactTestBitmask(ColliderTypeBird | ColliderTypeLand); this->groundNode->setPhysicsBody(groundBody); this->groundNode->setPosition(144, landHeight/2); this->addChild(this->groundNode); // init land this->landSpite1 = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("land")); this->landSpite1->setAnchorPoint(Point::ZERO); this->landSpite1->setPosition(Point::ZERO); this->addChild(this->landSpite1, 30); this->landSpite2 = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("land")); this->landSpite2->setAnchorPoint(Point::ZERO); this->landSpite2->setPosition(this->landSpite1->getContentSize().width-2.0f,0); this->addChild(this->landSpite2, 30); shiftLand = schedule_selector(GameLayer::scrollLand); this->schedule(shiftLand, 0.01f); this->scheduleUpdate(); auto contactListener = EventListenerPhysicsContact::create(); contactListener->onContactBegin = CC_CALLBACK_1(GameLayer::onContactBegin, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this); return true; }else { return false; } }
void EvilQueenBlade::Fire(){ this->scheduleOnce(schedule_selector(EvilQueenBlade::RealFire), 1.0f*option); }
bool CNFRockerLayer::InitLayer(CNF3DWorldLayer * pLayer,int nStageID) { do { //初始化父类 CC_BREAK_IF(CCLayerColor::initWithColor(ccc4(255,0,0,50))==false); //注册 CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-1,false); //设置层大小 setContentSize(CCSizeMake(200,200));//(CCSizeMake(SCREEN_WIDTH*0.5f,SCREEN_HEIGHT)); m_p3DLayer = pLayer; m_bIsTouching = false; m_bIsPublicCD = false; m_fRockerSpeed = _NF_ROCKER_SPEED_; //摇杆的移动速度 m_fRockerMaxDis = _NF_ROCKER_MAX_DIS_; //摇杆最大偏移量 m_nStageID = nStageID; //主角技能ID CNFProtagonist * pPro = dynamic_cast<CNFProtagonist *>(pLayer->getChildByTag(enTagProtagonist)); CC_BREAK_IF(pPro==NULL); m_nSkill_1_ID = pPro->GetSkillInfo_1().nSkill_SkillItemID; m_nSkill_2_ID = pPro->GetSkillInfo_2().nSkill_SkillItemID; m_nSkill_3_ID = pPro->GetSkillInfo_3().nSkill_SkillItemID; m_nSkill_4_ID = pPro->GetSkillInfo_4().nSkill_SkillItemID; m_nSkill_5_ID = pPro->GetSkillInfo_5().nSkill_SkillItemID; //创建摇杆背景 CCSprite * pRockerBg = CCSprite::create("gameui/rocker_bg.png"); CC_BREAK_IF(pRockerBg==NULL); //pRockerBg->setScale(2.5f); pRockerBg->setPosition(ccp(100,100)); addChild(pRockerBg,enZOrderFront,enTagRockerBg); pRockerBg->setOpacity(100.f); //创建摇杆 CCSprite * pRocker = CCSprite::create("gameui/rocker_ball.png"); CC_BREAK_IF(pRocker==NULL); pRocker->setPosition(pRockerBg->getPosition()); addChild(pRocker,enZOrderFront+1,enTagRocker); pRocker->setOpacity(100.f); //若为副本,则创建按钮 if (m_nStageID >= _NF_TOWN_OR_BATTLE_ID_ && m_nStageID <_NF_TOWN_FB_ID_) { /************************************************************************/ /* 创建按钮 */ /************************************************************************/ //创建菜单 CCMenu * pMenu = CCMenu::create(); CC_BREAK_IF(pMenu==NULL); pMenu->setPosition(CCPointZero); addChild(pMenu,enZOrderFront,enTagMenu); //创建普通攻击按钮 CCSprite * pCommon1 = CCSprite::create("gameui/skill_common.png"); CC_BREAK_IF(pCommon1==NULL); CCSprite * pCommon2 = CCSprite::create("gameui/skill_common.png"); CC_BREAK_IF(pCommon2==NULL); pCommon2->setOpacity(150.f); CCMenuItemSprite * pBtnCommon = CCMenuItemSprite::create(pCommon1,pCommon2,this,menu_selector(CNFRockerLayer::OnBtnCallBack)); CC_BREAK_IF(pBtnCommon==NULL); pBtnCommon->setPosition(ccp(SCREEN_WIDTH - 60,58)); pMenu->addChild(pBtnCommon,enZOrderFront,enTagBtnCommonAttack); CCLabelBMFont* pCommonAttackFont = CCLabelBMFont::create("1","fonts/mhp_num.fnt"); pCommonAttackFont->setPosition(pBtnCommon->getPosition()); this->addChild(pCommonAttackFont,enZOrderFront,enTagCommonAttackFont); CCSprite * pCommon3 = CCSprite::create("gameui/skill_common.png"); CC_BREAK_IF(pCommon3==NULL); pCommon3->setColor(ccRED); pCommon3->setOpacity(100.f); //创建普通攻击CD CCProgressTimer* pProgressCommonAttackCD = CCProgressTimer::create(pCommon3); CC_BREAK_IF(pProgressCommonAttackCD==NULL); pProgressCommonAttackCD->setType(kCCProgressTimerTypeRadial); pProgressCommonAttackCD->setMidpoint(ccp(0.5f,0.5f)); pProgressCommonAttackCD->setPercentage(0.f); pProgressCommonAttackCD->setPosition(pBtnCommon->getPosition()); this->addChild(pProgressCommonAttackCD,enZOrderFront+1,enTagCommonAttackCD); //创建技能按钮 for (int i=enTagBtnSkill1;i<=enTagBtnSkill5;i++) { char szName[NAME_LEN] = {0}; int skilltemp = -1; if(i==enTagBtnSkill1){ skilltemp = m_nSkill_1_ID; }else if(i==enTagBtnSkill2){ skilltemp = m_nSkill_2_ID; }else if(i==enTagBtnSkill3){ skilltemp = m_nSkill_3_ID; }else if(i==enTagBtnSkill4){ skilltemp = m_nSkill_4_ID; }else if(i==enTagBtnSkill5){ skilltemp = m_nSkill_5_ID; } if(skilltemp==-1){ continue; } sprintf(szName,"Skill/r%d_s%d.png",pPro->GetRoleID(),skilltemp); CCSprite * pSpr_n = CCSprite::create(szName); CC_BREAK_IF(pSpr_n==NULL); CCSprite * pSpr_p = CCSprite::create(szName); CC_BREAK_IF(pSpr_p==NULL);; pSpr_p->setColor(ccBLUE); CCSprite * pSpr_d = CCSprite::create(szName); CC_BREAK_IF(pSpr_d==NULL); pSpr_d->setOpacity(150.f); CCSprite * pSpr_CD = CCSprite::create(szName); CC_BREAK_IF(pSpr_CD==NULL); pSpr_CD->setColor(ccRED); //创建技能按钮 CCMenuItemSprite * pBtn = CCMenuItemSprite::create(pSpr_n,pSpr_p,pSpr_d,this,menu_selector(CNFRockerLayer::OnBtnCallBack)); CC_BREAK_IF(pBtn==NULL); pMenu->addChild(pBtn,enZOrderFront,i); if(i==enTagBtnSkill1) pBtn->setPosition(ccp(pBtnCommon->getPositionX()+10,pBtnCommon->getPositionY()+90)); else if(i==enTagBtnSkill2) pBtn->setPosition(ccp(pBtnCommon->getPositionX()-110,pBtnCommon->getPositionY()-5)); else if(i==enTagBtnSkill3) pBtn->setPosition(ccp(pBtnCommon->getPositionX()-70,pBtnCommon->getPositionY()+70)); else if(i==enTagBtnSkill4) pBtn->setPosition(ccp(pBtnCommon->getPositionX()-200,pBtnCommon->getPositionY()-5)); else if(i==enTagBtnSkill5) pBtn->setPosition(ccp(pBtnCommon->getPositionX()+10,pBtnCommon->getPositionY()+170)); //创建技能CD CCProgressTimer* pProgress = CCProgressTimer::create(pSpr_p); CC_BREAK_IF(pProgress==NULL); pProgress->setType(kCCProgressTimerTypeRadial); pProgress->setMidpoint(ccp(0.5f,0.5f)); pProgress->setPercentage(0.f); pProgress->setPosition(pBtn->getPosition()); this->addChild(pProgress,enZOrderFront+1,i+100); //技能CD标签 = 技能标签 + 100 //创建公共CD CCProgressTimer* pProgressCD = CCProgressTimer::create(pSpr_CD); CC_BREAK_IF(pProgressCD==NULL); pProgressCD->setType(kCCProgressTimerTypeRadial); pProgressCD->setMidpoint(ccp(0.5f,0.5f)); pProgressCD->setPercentage(0.f); pProgressCD->setPosition(pBtn->getPosition()); this->addChild(pProgressCD,enZOrderFront+2,i+200); //技能CD标签 = 技能标签 + 200 pProgressCD->setVisible(false); } } //更新函数 schedule(schedule_selector(CNFRockerLayer::update)); return true; } while (false); CCLog("Fun CNFRockerLayer::InitLayer Error!"); return false; }
bool AntiVisibleTower::init() { if (!Sprite::init()) //如果忘记了这句话则会在runApplication报错 { return false; } instance = GameManager::getInstance(); setScope(300); setAttack(0); setRate(5);//4秒钟开火一次 setTowerType(3); setIsSelected(false); setGrade(0);//开始没有等级 setPower(40);//塔消耗电力 setMove(false);//开始不处于移动状态 setIsPowerEnough(true);//开始状态电力足够 setIsPowerConsumption(true);//该塔耗电 nearestEnemy = nullptr; towerSprite = Sprite::create("towerItem/Item99.png"); addChild(towerSprite, 5); gradeSprite = Sprite::create("level1.png"); gradeSprite->setAnchorPoint(Point(0, 0)); gradeSprite->setPosition(this->getPosition().x + 10, -towerSprite->getBoundingBox().size.height / 2); gradeSprite->setOpacity(0);//开始让其不可见 addChild(gradeSprite, 6); noPowerSprite = Sprite::create("noPower.png"); noPowerSprite->setAnchorPoint(Point(0.5, 0)); noPowerSprite->setScale(1.4); noPowerSprite->setPosition(towerSprite->getBoundingBox().size.width / 2 - 70, towerSprite->getBoundingBox().size.height - 40); noPowerSprite->setVisible(false); addChild(noPowerSprite, 7); //血量条背景图片 towerHpSprite = Sprite::create("manaBarBg.png"); towerHpSprite->setPosition(noPowerSprite->getPosition()-Point(0,25)); towerHpSprite->setScale(0.8); addChild(towerHpSprite, 10); //炮塔血量 hp = 4; //炮塔血量进度条 towerHp = ProgressTimer::create(Sprite::create("soldierProduceTimeBar.png")); //参数是一个图片sprite towerHp->setScaleX(2); towerHp->setScaleY(5.2); towerHp->setType(ProgressTimer::Type::BAR); towerHp->setMidpoint(Point(0, 0.5f)); towerHp->setBarChangeRate(Point(1, 0)); towerHp->setPercentage(100); towerHp->setPosition(Point(towerHpSprite->getContentSize().width / 2, towerHpSprite->getContentSize().height / 3 * 2 - 10)); towerHpSprite->addChild(towerHp, 5); //初始化不可见 towerHp->setVisible(false); towerHpSprite->setVisible(false); schedule(schedule_selector(AntiVisibleTower::shoot), 0.1f); schedule(schedule_selector(AntiVisibleTower::checkNearestEnemy, this), 0.2); addTouch();//添加触摸事件 return true; }
// on "init" you need to initialize your instance bool MainScene::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); ////////////////////////////////////////////////////////////////////////// // add your codes below... ////////////////////////////////////////////////////////////////////////// // 1. Add a menu item with "X" image, which is clicked to quit the program. // Create a "close" menu item with close icon, it's an auto release object. /* CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(GameScene::menuCloseCallback)); CC_BREAK_IF(! pCloseItem); // Place the menu item bottom-right conner. pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20)); // Create a menu with the "close" menu item, it's an auto release object. CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); // Add the menu to HelloWorld layer as a child layer. this->addChild(pMenu, 1); */ // 2. Add a label shows "Hello World". // Create a label and initialize with string "Hello World". /* CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); CC_BREAK_IF(! pLabel); // Get window size and place the label upper. CCSize size = CCDirector::sharedDirector()->getWinSize(); pLabel->setPosition(ccp(size.width / 2, size.height - 50)); // Add the label to HelloWorld layer as a child layer. this->addChild(pLabel, 1); */ // 3. Add add a splash screen, show the cocos2d splash image. size = CCDirector::sharedDirector()->getWinSize(); CCSprite* pSprite = CCSprite::create("images/background.png"); CC_BREAK_IF(! pSprite); // Place the sprite on the center of the screen pSprite->setPosition(ccp(size.width/2, size.height/2)); // Add the sprite to HelloWorld layer as a child layer. this->addChild(pSprite, 0); CCMenuItemFont* itemPlay = CCMenuItemFont::create("Play", this, menu_selector(MainScene::menuPlayCallback)); CCMenuItemFont* itemOptions = CCMenuItemFont::create("Options", this, menu_selector(MainScene::menuOptionsCallback)); CCMenuItemFont* itemScores = CCMenuItemFont::create("Scores", this, menu_selector(MainScene::menuScoresCallback)); CCMenuItemFont* itemAbout = CCMenuItemFont::create("About", this, menu_selector(MainScene::menuAboutCallback)); CCMenuItemFont* itemQuit = CCMenuItemFont::create("Quit", this, menu_selector(MainScene::menuCloseCallback)); CCMenu* menu = CCMenu::create(itemPlay, itemOptions, itemScores, itemAbout, itemQuit, NULL); menu->alignItemsVerticallyWithPadding(20); this->addChild(menu, 1); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( "images/images.plist", "images/images.png"); CCTexture2D* texture = CCTextureCache::sharedTextureCache()->textureForKey("images/images.png"); node = CCSpriteBatchNode::createWithTexture(texture); this->addChild(node); this->schedule(schedule_selector(MainScene::update), 0.1f); bRet = true; } while (0); return bRet; }
void BrokableWall::updateContactState(float dt) { this->unschedule(schedule_selector(BrokableWall::updateContactState)); this->m_bIsCanContact = true; }
DiscoLayer::DiscoLayer() { this->schedule(schedule_selector(DiscoLayer::update)); }
void SchedulerUpdateFromCustom::stopUpdate(ccTime dt) { unscheduleUpdate(); unschedule(schedule_selector(SchedulerUpdateFromCustom::stopUpdate)); }
void CCHttpClient::destroyInstance() { CCAssert(s_pHttpClient, ""); CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(CCHttpClient::dispatchResponseCallbacks), s_pHttpClient); s_pHttpClient->release(); }
void BulletLayer::StopShoot() { this->unschedule(schedule_selector(BulletLayer::AddBullet)); }
void GameLayer::checkingCollision() { CCArray *readyToRemoveEnemies = CCArray::create(); readyToRemoveEnemies->retain(); for (unsigned int i = 0; i < enemies->count(); i++) { CCSprite *enemy = (CCSprite *) enemies->objectAtIndex(i); //玩家 if (enemy->boundingBox().intersectsRect(playerPlane->boundingBox())) { this->unschedule(schedule_selector(GameLayer::checkingCollision)); this->unschedule(schedule_selector(GameLayer::shootBullet)); backgroundSprite_1->stopAllActions(); backgroundSprite_2->stopAllActions(); this->unschedule(schedule_selector(GameLayer::showEnemy)); this->unschedule(schedule_selector(GameLayer::showProp)); //printf(": hero_blowup_%i.png\n", i); CCFiniteTimeAction *gameOverAction = this->frameAnimationWithFrameName("hero_blowup_%i.png", 4, 0.1f, 1); CCCallFuncND *actionEnd = CCCallFuncND::create(this, callfuncND_selector(GameLayer::gameOverBlowUpEndedWithAction), playerPlane); playerPlane->runAction( CCSequence::create(gameOverAction, actionEnd, NULL)); } CCObject* it = NULL; CCARRAY_FOREACH(bullets, it) { CCSprite *bullet = dynamic_cast<CCSprite*>(it); if (enemy->boundingBox().intersectsRect(bullet->boundingBox())) { if (enemy->boundingBox().origin.y + enemy->boundingBox().size.height < winSize.height) { if (this->getEnemyHpWithTag(enemy->getTag()) >= 2 && superBullet) { enemy->setTag(enemy->getTag() - 2); } else { enemy->setTag(enemy->getTag() - 1); } int hp = this->getEnemyHpWithTag(enemy->getTag()); if (hp <= 0) { readyToRemoveEnemies->addObject(enemy); } else { int type = this->getEnemyTypeWithTag(enemy->getTag()); if (type == 2) { enemy->setDisplayFrame( CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( "enemy2_hit_1.png")); } else if (type == 3) { CCFiniteTimeAction *hitAction = this->frameAnimationWithFrameName( CCString::createWithFormat( "enemy3_hit_%i.png", i)->getCString(), 2, 0.1f, 1); enemy->runAction(hitAction); } } } } } }
void Test4::delay4(float dt) { unschedule(schedule_selector(Test4::delay4)); removeChildByTag(3, false); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } //加一个label LabelScore = CCLabelTTF::create("score","arial",30); LabelScore->setColor(ccBLACK); LabelScore->retain(); LabelScore->setPosition(ccp(340, 300) ); this->addChild(LabelScore, 1); LabelScore = CCLabelTTF::create("0","arial",30); LabelScore->setColor(ccBLACK); LabelScore->retain(); LabelScore->setPosition(ccp(400, 300) ); this->addChild(LabelScore, 1); scheduleUpdate(); currentScore = 0; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label /* CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); */ // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("00.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); /*CCSprite* key1=CCSprite::create("1.png"); key1->setPosition(ccp(100,160)); key1->setAnchorPoint(ccp(0,0.5)); this->addChild(key1); */ //设置随机跳出按键 schedule(schedule_selector(HelloWorld::timeset),0.5f); srand(time(0)); //delete //m_pSprite = CCSprite::create("Projectile.png"); setTouchEnabled(true); //m_pSprite->setPosition(ccp(visibleSize.width/2+origin.x,visibleSize.height/2+origin.y)); //this->addChild(m_pSprite,1); CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("weifengtangtang.mp3",true); return true; }