void InGameLayer::replayCallBack(Ref* sender)
{
	isTouched = false;
	this->schedule(SEL_SCHEDULE(&InGameLayer::moveAllBalls),0.02f);
	this->schedule(SEL_SCHEDULE(&InGameLayer::timeFunCount),1.0f);

}
Example #2
0
void GuideLayer::GameStart()
{
	this->schedule(SEL_SCHEDULE(&GuideLayer::GameStep),0.02f); 
	this->schedule(SEL_SCHEDULE(&GuideLayer::createCarWithTimer),CCRANDOM_0_1()*3 + 2);
	this->schedule(SEL_SCHEDULE(&GuideLayer::ChangeCd),1.0f);
	
	
}
void InGameLayer::onEnterTransitionDidFinish()
{
	Layer::onEnterTransitionDidFinish();
	//时间步进器
	this->schedule(SEL_SCHEDULE(&InGameLayer::moveAllBalls),0.02f);
	//添加文本计时步进器
	this->schedule(SEL_SCHEDULE(&InGameLayer::timeFunCount),1.0f);
}
Example #4
0
void FighterMgr::start()
{
    Director::getInstance()->getScheduler()->schedule(SEL_SCHEDULE(&FighterMgr::checkRun), this, 0, false );
    Director::getInstance()->getScheduler()->schedule(SEL_SCHEDULE(&FighterMgr::passiveAttack), this, 5, false);
    
    for(Skill* skill : skills){
        skill->start();
    }
    
    this->state=Efstate::idle;
    this->startAttack(skills.back());
}
Example #5
0
void SchedulerIssue2268::onEnter()
{
	SchedulerTestLayer::onEnter();

	testNode = TestNode2::create();
	testNode->retain();
	testNode->schedule(SEL_SCHEDULE(&TestNode::update));
	this->addChild(testNode);


	this->scheduleOnce(SEL_SCHEDULE(&SchedulerIssue2268::update), 0.25f);
}
Example #6
0
void AppDelegate::initGame(){
    
	pObj=new CCObject();
    
    //cocos2d::extension::CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary()->registerCCNodeLoader("LayerUI",LayerUILoader::loader());
    
	Facade::registerCommands();
    
	if(!Facade::IsMock){
		Client* client=Client::GetInstance();
		bool b=client->connet(Facade::Ip, Facade::Port);
		if(b){
			CCDirector::sharedDirector()->getScheduler()->scheduleSelector(SEL_SCHEDULE(&AppDelegate::excuteCommand), pObj, 0.01f, false);
			client->setConfig("18602122551", "PASSPORT");
			Facade::send(CommandHead::Check,Facade::Version);
		}
	}
    
    //CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");
	
	//³õʼ»¯ÅäÖÃ
	//¶ÁÈ¡ÅäÖÃjson
//	const char * configFileName= "config.txt";
//	string configStr=FileUtil::read(configFileName);
	//½âÎöjson
//	Facade::Emails=ConfigUtil::parseEmail(configStr.c_str());
//	CCLOG("id==%d",Facade::Emails[1].id);
//	CCLOG("content==%s",Facade::Emails[1].content.c_str());

	//¶ÁÈ¡ÓïÑÔÎļþ
	
	Facade::Langs=ConfigUtil::parseLang("langs","zh-CN");
}
Example #7
0
AppDelegate::~AppDelegate()
{
	SmartRes::sharedRes()->release();

	CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(SEL_SCHEDULE(&AppDelegate::excuteCommand),pObj);
	delete pObj;
}
Example #8
0
void Pattern::fillPattern(){
    if (_async) {
        pthread_mutex_lock(&_mutex);
    }
    _colorCounter = 0;
    
    log("start      %ld %ld", ScribbleUtil::getInstance()->getCurrentTimeByMicroseconds(), time(nullptr));
    for (int r = 1; r < this->getSize().height; ++r) {
        for (int c = 1; c < this->getSize().width; ++c) {
            Color4B lColor = this->getPixelColor(c, this->getSize().height - r);
            if (lColor.a <= 0) {
                Color4B lFillColor = _colors.at(_colorCounter);
                ++_colorCounter;
                //    log("lFillColor %d %d %d", lFillColor.r, lFillColor.g, lFillColor.b);
                
                //                log("pre fill %d: %d %d", _colorCounter, c, r);
                this->fill(lFillColor, this->convertToWorldSpace(Vec2(c, r)));
            }
        }
        _patternLoadPercent = ((float)r) / this->getSize().height;
    }
    log("pre fill number %d", _colorCounter);
    log("middle     %ld %ld", ScribbleUtil::getInstance()->getCurrentTimeByMicroseconds(), time(nullptr));
    if (_async) {
        pthread_mutex_unlock(&_mutex);
    }

    this->scheduleOnce(SEL_SCHEDULE(&Pattern::refreshPatternData), 0);
}
void NodeChildrenMenuLayer::onExitTransitionDidStart()
{
    auto director = Director::getInstance();
    auto sched = director->getScheduler();

    sched->unscheduleSelector(SEL_SCHEDULE(&NodeChildrenMenuLayer::dumpProfilerInfo), this);
}
void NodeChildrenMenuLayer::onEnterTransitionDidFinish()
{
    auto director = Director::getInstance();
    auto sched = director->getScheduler();

    CC_PROFILER_PURGE_ALL();
    sched->scheduleSelector(SEL_SCHEDULE(&NodeChildrenMenuLayer::dumpProfilerInfo), this, 2, false);
}
void PerformceAllocScene::onExitTransitionDidStart()
{
    Scene::onExitTransitionDidStart();
    
    auto director = Director::getInstance();
    auto sched = director->getScheduler();

    sched->unscheduleSelector(SEL_SCHEDULE(&PerformceAllocScene::dumpProfilerInfo), this);
}
Example #12
0
void  SpriteMainScene::endAutoTest()
{
    SpriteMainScene::_s_autoTest = false;
    
    auto director = Director::getInstance();
    auto sched = director->getScheduler();
    
    sched->unscheduleSelector( SEL_SCHEDULE( &SpriteMainScene::updateAutoTest ), this );
}
Example #13
0
void GameScene::doCheck()
{
    bool isGameOver = true;
    
    //结束边界  4*4的card数值>0 且  相邻card没有相同数值
    //4*4的card数值>0 不能在创建Number
    //判断每一个的上下左右和自己是否相同
    for (int y = 0; y < 4; y++)
    {
        for (int x = 0; x < 4; x++)
        {
            if (cardArr[x][y]->getNumber() == 0 ||
                (x<3 && cardArr[x][y]->getNumber() == cardArr[x+1][y]->getNumber()) ||
                (x>0 && cardArr[x][y]->getNumber() == cardArr[x-1][y]->getNumber()) ||
                (y<3 && cardArr[x][y]->getNumber() == cardArr[x][y+1]->getNumber()) ||
                (y>0 && cardArr[x][y]->getNumber() == cardArr[x][y-1]->getNumber()) )
            {
                isGameOver = false;
            }
        }
    }
    if (isWin()) {
        
        successLayer = LayerColor::create(Color4B(0, 0, 0, 180));
        Size winSize = Director::getInstance()->getWinSize();
        Point centerPos = Point(winSize.width / 2, winSize.height / 2);
        auto gameOverTitle = Label::createWithSystemFont("YOU WIN","Consolas",80);
        gameOverTitle->setPosition(centerPos);
        successLayer->addChild(gameOverTitle);
        
        getParent()->addChild(successLayer,1);
        
        scheduleOnce(SEL_SCHEDULE(&GameScene::removeSuccessLayer), 2);
        return;
    }
    
    //isGameOver = true;
    if (isGameOver)
    {
        log("game over");
        UserDefault::getInstance()->setBoolForKey("history", false);
        
        HighScore::getInstance()->setScore(score);
        GameOverLayer *gameoverLayer = GameOverLayer::create(Color4B(0, 0, 0, 180));
        getParent()->addChild(gameoverLayer,1);
        
        Director::getInstance()->pause();
    }
    else
    {
        if (shouldCreateCardNumber()) {
            createCardNumber();
            
            saveStatus();
        }
    }
}
void PerformceAllocScene::onEnterTransitionDidFinish()
{
    Scene::onEnterTransitionDidFinish();

    auto director = Director::getInstance();
    auto sched = director->getScheduler();

    CC_PROFILER_PURGE_ALL();
    sched->scheduleSelector(SEL_SCHEDULE(&PerformceAllocScene::dumpProfilerInfo), this, 2, false);
}
Example #15
0
void SchedulerIssue10232::onEnter()
{
    SchedulerTestLayer::onEnter();

    this->scheduleOnce(SEL_SCHEDULE(&SchedulerIssue2268::update), 0.25f);

    this->scheduleOnce([](float dt){
        log("SchedulerIssue10232:Schedules a lambda function");
    }, 0.25f,"SchedulerIssue10232");
}
Example #16
0
void COpenLock::ResetLockInfo()
{
	Open_lockCfg* lockCfg = OpenLockData.get(GetLockId());
	if(!lockCfg) return;

	int randRange = abs(lockCfg->random_min)+lockCfg->random_max;
	srand (time(NULL));
	m_openDegreeMin = rand()%randRange + 1;
	if(m_openDegreeMin>lockCfg->random_max)
	{
		m_openDegreeMin = lockCfg->random_max - m_openDegreeMin;
	}
	m_openDegreeMax = m_openDegreeMin + lockCfg->section;
	m_openDegreeMiddle = (m_openDegreeMin+m_openDegreeMax)/2;

	SetMaxTime(lockCfg->max_time);
	SetLeftTime(lockCfg->max_time);
	unschedule(SEL_SCHEDULE(&COpenLock::ScheduleLeftTime));
	schedule(SEL_SCHEDULE(&COpenLock::ScheduleLeftTime),1.0f,GetMaxTime()+1,0.0f);
}
Example #17
0
void NetStateChecker::QuickSendRqsToServer()
{
    OnlineNetworkManager::sShareInstance()->sendReqNetStateMessage();
    bSendContent = true;
    mTimeInMs = GetTimeWithLua();
    CCDirector::sharedDirector()->getScheduler()->scheduleSelector(SEL_SCHEDULE(&NetStateChecker::quick_udpate),
                                                                   this,
                                                                   1.0f,
                                                                   false);
    m_fLifeHelloTime = -10.f;
}
Example #18
0
bool CFScoreBoard::init(int score){
    if(!CCSprite::init()){
        return false;
    }
    this->score = score;
    CCSize size = this->getContentSize();
    width = size.width;
    height = size.height;
    this->schedule(SEL_SCHEDULE(&CFScoreBoard::doAutoScore), 1);
    return true;
}
Example #19
0
void NetStateChecker::Start()
{
	if (bStartTesting)
	{
		CCDirector::sharedDirector()->getScheduler()->scheduleSelector(SEL_SCHEDULE(&NetStateChecker::update), 
			this, 
			10.0f, 
			false);

		SendRqsToServer();
	}
}
Example #20
0
void SpriteMainScene::onExit()
{
    if ( SpriteMainScene::_s_autoTest )
    {
        auto director = Director::getInstance();
        auto sched = director->getScheduler();
        
        sched->unscheduleSelector(SEL_SCHEDULE(&SpriteMainScene::updateAutoTest), this );
    }
    
    Scene::onExit();
}
Example #21
0
void TanSuoLayer::refreshDisconverTime(unsigned int count, unsigned int tansuoCount)
{
	//unsigned int iTotalCount =  CS::getDiscoverLimitTimes(MyselfManager::getManager()->getMyZhuJueData()->getVipLevel());
	CCLabelTTF *label = (CCLabelTTF*)mBg->getChildByTag(Tag_Label_CurNum);
	if (label)
	{
		CCString temp;
		temp.initWithFormat("%u", count);
		label->setString(temp.getCString());
	}
	int xunBaoCount = CS::getDiscoverLimitTimes(MyselfManager::getManager()->getMyZhuJueData()->getVipLevel());//寻宝次数上限
	if (m_nHadCount == xunBaoCount)
	{
		m_nRefreshTime = 360;
	}
	m_nHadCount = count;
	
	if (count < xunBaoCount)
	{
		schedule(SEL_SCHEDULE(&TanSuoLayer::refreshTime),1.0f);
	}
	if (tansuoCount >= MAX_TANSUOTIMES)
	{
		mBg->removeChildByTag(Tag_Label_Haixu);
		mBg->removeChildByTag(Tag_Label_ShengyuNum);
		mBg->removeChildByTag(Tag_Label_DianLiang);

		m_tHaixuTTF = NULL;
		CCLabelTTF *pTTF = (CCLabelTTF*)mBg->getChildByTag(Tag_Label_YiDianLiang);
		if (pTTF)
		{
			pTTF->removeFromParent();
		}
		CCString* temp = CCString::create(LFStrings::getValue("XunBaoYiJing_DianLiang_String").c_str());
		CCLabelTTF *yidianliangLabel = CCLabelTTF::create(temp->getCString(), fontStr_kaiti, m_nFontSize, CCSize(0,0), kCCTextAlignmentCenter);
		mBg->addChild(yidianliangLabel, 1, Tag_Label_YiDianLiang);
		//yidianliangLabel->setAnchorPoint(ccp(0,0.5));
		yidianliangLabel->setPosition(ccp( mBg->getContentSize().width / 2, 44));
		yidianliangLabel->setColor(fonColor_PuTong);
	}
	else
	{
		int shengyuTimes = MAX_TANSUOTIMES - tansuoCount;
		//CCString *str = CCString::createWithFormat("%s%d%s",LFStrings::getValue("XunBaoHaixu_String").c_str(),shengyuTimes,LFStrings::getValue("XunBaoDianLiang_String").c_str());
		CCLabelTTF *usedNum = (CCLabelTTF*)mBg->getChildByTag(Tag_Label_Haixu);
		if (usedNum)
		{
			usedNum->setString(CCString::createWithFormat("%d",shengyuTimes)->getCString());
		}
	}
	
}
Example #22
0
void COpenLock::ScheduleLeftTime(float dt)
{
	if (m_nLeftTime>=0)
	{
		m_pCountNum->setString(CCString::createWithFormat("%d",GetLeftTime())->getCString());
		SetLeftTime(GetLeftTime()-1);
	}
	else
	{
		unschedule(SEL_SCHEDULE(&COpenLock::ScheduleLeftTime));
		gGameUILayer->close(this);
	}
}
Example #23
0
void COpenLock::onClose()
{
	unschedule(SEL_SCHEDULE(&COpenLock::ScheduleLeftTime));

	CChests* pChests = dynamic_cast<CChests*>(gMap->getObjectManager()->getObject(GetItemBoxId()));
	if(pChests)
	{
		pk::C2GS_OPEN_TREAS_Req cmd;
		cmd.id = GetItemBoxId();
		cmd.open_state = (int)CChests::ChestsStatus_Idle;
		cmd.Send(gNetSocket);
	}
	SetItemBoxId(0);
}
Example #24
0
SocketConn::SocketConn()
{
	Director::getInstance()->getScheduler()->scheduleSelector(SEL_SCHEDULE(&SocketConn::update), this, 0.1f, false);

	sendQueue = new queue<Packet*>();
	recvQueue = new queue<Packet*>();

	connected = false;
	recvThread = nullptr;
	sendThread = nullptr;
	odSocket = nullptr;
	thread = nullptr;

}
Example #25
0
void Stage04::StagePass()
{
	this->unschedule(SEL_SCHEDULE(&Stage04::createCarWithTimer));
	bus = Sprite::create("bus.png");
	bus->setPosition(winSize.width + 400, 150);
	this->addChild(bus);
	DelayTime* busdelaytime1 = DelayTime::create(1);
	MoveTo* busmoveto1 = MoveTo::create(3,ccp(winSize.width / 2, 150));
	DelayTime* busdelaytime2 = DelayTime::create(2);
	MoveTo* busmoveto2 = MoveTo::create(3,ccp(-400, 150));
	auto busaction = Sequence::create(busdelaytime1,busmoveto1, busdelaytime2, busmoveto2, NULL);
	bus->runAction(busaction);

	auto s	= getChildByTag(1);
	float o = winSize.width / 2 - s->getPosition().x;
	float a = 100 - s->getPosition().y;
	float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );

	if( a < 0 ) 
	{
		if(  o < 0 )
			at = 180 + fabs(at);
		else
			at = 180 - fabs(at);    
	}
	RotateTo* rotateto =  RotateTo::create(0.5, at);
	DelayTime* herodelaytime = DelayTime::create(4);
	MoveTo* heromoveto = MoveTo::create(1,ccp(winSize.width / 2, 150));
	FadeOut* herofadeout = FadeOut::create(0.5f);
	auto heroaction = Sequence::create(rotateto,herodelaytime, heromoveto, herofadeout, NULL);
	s->runAction(heroaction);

	winboard = Sprite::create("winboard.png");
	winboard->setPosition(winSize.width / 2, winSize.height + 250);
	this->addChild(winboard);
	LabelTTF* playTTF1		=	LabelTTF::create("next stage","ARNPRIOR",32);
	MenuItemLabel* item1		=	MenuItemLabel::create(playTTF1,CC_CALLBACK_1(Stage04::WinBoardNextCallBack,this));
	LabelTTF* playTTF2		=	LabelTTF::create("main menu","ARNPRIOR",32);
	MenuItemLabel* item2		=	MenuItemLabel::create(playTTF2,CC_CALLBACK_1(Stage04::WinBoardMainMenuCallBack,this));
	item1->setPositionY(item1->getPositionY() + 20);
	item2->setPositionY(item2->getPositionY() - 20);
	Menu* playMenu			=	Menu::create(item1, item2, NULL);
	playMenu->setPosition(270,130);
	winboard->addChild(playMenu);
	DelayTime* boarddelaytime = DelayTime::create(7);
	MoveTo* boardmoveto = MoveTo::create(1,ccp(winSize.width / 2, winSize.height / 2));
	auto boardaction = Sequence::create(boarddelaytime, boardmoveto, NULL);
	winboard->runAction(boardaction);
}
Example #26
0
void SpriteMainScene::onEnter()
{
    Scene::onEnter();
    
    if ( SpriteMainScene::_s_autoTest )
    {
        _vecFPS.clear();
        _executeTimes = 0;
        
        auto director = Director::getInstance();
        auto sched = director->getScheduler();
        
        sched->scheduleSelector(SEL_SCHEDULE(&SpriteMainScene::updateAutoTest), this, 0.2f, false);
        
    }
}
Example #27
0
void  SpriteMainScene::finishAutoTest()
{
    SpriteMainScene::_s_autoTest = false;
    auto director = Director::getInstance();
    auto sched = director->getScheduler();
    sched->unscheduleSelector( SEL_SCHEDULE( &SpriteMainScene::updateAutoTest ), this);
    
    auto autoTestMenu = dynamic_cast<Menu*>(getChildByTag(kTagAutoTestMenu));
    if (nullptr != autoTestMenu)
    {
        auto menuItemFont = dynamic_cast<MenuItemFont*>(autoTestMenu->getChildByTag(1));
        if (nullptr != menuItemFont)
        {
            menuItemFont->setString("Auto Test finish");
        }
    }
    
    log("Sprite performance test is  finish ");
}
Example #28
0
void ShoppingLayer::successCallBack(bool buyOver)
{
	CCLOG("ButtonTag_Buy over!!!");
	if (buyOver)
	{
		// 成功
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
		//umeng::MobClickCpp::buy(sInstance -> payID.c_str(), 1, 1000);
#endif

		
		this->scheduleOnce(SEL_SCHEDULE(&ShoppingLayer::buySuccess), 0.01);
		//buySuccess(0);
		
	} else
	{
		sInstance->showShoppingTip(false);
	}
}
Example #29
0
bool GameScene::init() 
{     
	if (!Layer::init())     {
		return false;     
	}       
	Size visibleSize = Director::getInstance()->getVisibleSize();       
	auto labelBack = Label::createWithSystemFont("Main Menu", "Arial", 16);
	auto itemBack = MenuItemLabel::create(labelBack, CC_CALLBACK_1(GameScene::menuBackToMain, this));     
	itemBack->setPosition(Point(visibleSize.width, 0));     
	itemBack->setAnchorPoint(Point::ANCHOR_BOTTOM_RIGHT);       
	auto menu = Menu::create(itemBack, NULL);     
	menu->setPosition(Point(0, 0));     
	this->addChild(menu);
    
    this->labelScore = Label::createWithSystemFont("Score: 0", "Arial", 22);
	this->labelScore->setPosition(Point(visibleSize.width- labelScore->getContentSize().width,
                             visibleSize.height - labelScore->getContentSize().height));
	this->addChild(labelScore);
    
    winWidth=visibleSize.width;
    winHeight=visibleSize.height;
    score=0;
	speed=0.1f;
    gameOverFlag=false;
    gameOverDelay=1.0f/speed;

    //初始化蛇
    snakeLength=3;
    snakeNodeWidth=18;
    snakeStep=1;
    snakeAllStep=0;
    controlDir=DIR_DEF::LEFT;
    int x=winWidth-snakeLength*snakeNodeWidth-10;
    int y=rand()%winHeight-snakeNodeWidth;
    x=(x/snakeNodeWidth)*snakeNodeWidth;
    y=(y/snakeNodeWidth)*snakeNodeWidth;
    

    for(int i=0;i<snakeLength;i++){
        auto sprite = Sprite::create("snake.png");
        auto node = new SnakeNode();
        node->x=x+snakeNodeWidth*i;
        node->y=y;
        int dir=controlDir;
        node->sprite=sprite;
        node->sprite->setPosition(Point(node->x, node->y));
        node->sprite->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
        

        this->addChild(node->sprite);
        snake.pushBack(node);
        if(i>0){
            for(int j=0;j<snakeStep;j++){
                auto dirNode = new DirNode();
                dirNode->dir=dir;
                dirChain.pushBack(dirNode);
            }
        }
    }
    
    //初始化蛋
    egg =genEgg();
    this->addChild(egg->sprite);
    
    //建立触摸监听
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
    listener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this);
    this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);
    
    //建立键盘监听
    auto listenerKeyboard = EventListenerKeyboard::create();
    listenerKeyboard->onKeyPressed = CC_CALLBACK_2(GameScene::onKeyPressed, this);
    listenerKeyboard->onKeyReleased = CC_CALLBACK_2(GameScene::onKeyReleased, this);
    
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerKeyboard, this);

    CocosDenshion::SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.1f);
    CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(BACKGROUND_SOUND);

    
    this->schedule(SEL_SCHEDULE(&GameScene::play), speed);
    
	return true; 
}
Example #30
0
void NetStateChecker::Stop()
{
	CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(SEL_SCHEDULE(&NetStateChecker::Update), this);
}