Пример #1
0
void FailScene::setScore( int score, int bestScore)
{
	String* str = String::createWithFormat("%d", score);
	LabelTTF* scoreValTxt = (LabelTTF* )this->getChildByTag(scoreValTxtTag);
	scoreValTxt->setString(str->_string);

	str = String::createWithFormat("%d", bestScore);
	LabelTTF* bestScoreValTxt = (LabelTTF* )this->getChildByTag(bestScoreValTxtTag);
	bestScoreValTxt->setString(str->_string);
}
Пример #2
0
	void NetworkTestView::get() {
		const char* url = "https://raw.github.com/sunfish-shogi/coconut-sample/master/README.md";
		LabelTTF* lblResult = (LabelTTF*)_scene->getChildByTag(TAG_ROOT)->getChildByTag(TAG_RESULT);
		lblResult->setString("");
		_http.get(url, [=](const HttpManager::Response& response) {
			if (response.code == 200) {
				std::string body(response.body.buffer(), response.body.size());
				lblResult->setString(body);
				std::cout << body << std::endl;
			} else {
				log("ERROR: HTTP Code=%d", response.code);
				log("ERROR: %s", response.error);
			}
		});
	}
Пример #3
0
TableViewCell* TableViewTestLayer::tableCellAtIndex(TableView *table, unsigned int idx)
{
    String *string = String::createWithFormat("%d", idx);
    TableViewCell *cell = table->dequeueCell();
    if (!cell) {
        cell = new CustomTableViewCell();
        cell->autorelease();
        Sprite *sprite = Sprite::create("Images/Icon.png");
        sprite->setAnchorPoint(Point::ZERO);
        sprite->setPosition(Point(0, 0));
        cell->addChild(sprite);

        LabelTTF *label = LabelTTF::create(string->getCString(), "Helvetica", 20.0);
        label->setPosition(Point::ZERO);
		label->setAnchorPoint(Point::ZERO);
        label->setTag(123);
        cell->addChild(label);
    }
    else
    {
        LabelTTF *label = (LabelTTF*)cell->getChildByTag(123);
        label->setString(string->getCString());
    }


    return cell;
}
Пример #4
0
void TestAsynchronousLoading::onEnter()
{
    ArmatureTestLayer::onEnter();

    //CCLOG("armature version : %s", armatureVersion());

    backItem->setEnabled(false);
    restartItem->setEnabled(false);
    nextItem->setEnabled(false);

    char pszPercent[255];
    sprintf(pszPercent, "%s %f", subtitle().c_str(), 0.0f);
    LabelTTF *label = (LabelTTF *)getChildByTag(10001);
    label->setString(pszPercent);


    //! create a new thread to load data
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));

    //! load data directly
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml");
    //	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Cowboy.ExportJson");

}
Пример #5
0
bool CChooseLetterWindow::init()
{	   
	m_Back = Sprite::create("choose_letter.png");
	m_Back->setPosition(600,384); 
	m_Back->setVisible(false);
	addChild(m_Back);
	std::vector<char> m_Letters;
	m_Letters.resize(26);
	m_Letters[0] = 'a'; m_Letters[1] = 'b'; m_Letters[2] = 'c'; m_Letters[3] = 'd'; m_Letters[4] = 'e'; m_Letters[5] = 'f'; m_Letters[6] = 'g'; 
	m_Letters[7] = 'h'; m_Letters[8] = 'i'; m_Letters[9] = 'j'; m_Letters[10] = 'k'; m_Letters[11] = 'l'; m_Letters[12] = 'm'; m_Letters[13] = 'n'; 
	m_Letters[14] = 'o'; m_Letters[15] = 'p'; m_Letters[16] = 'q'; m_Letters[17] = 'r'; m_Letters[18] = 's'; m_Letters[19] = 't'; m_Letters[20] = 'u'; 
	m_Letters[21] = 'v'; m_Letters[22] = 'w'; m_Letters[23] = 'x'; m_Letters[24] = 'y'; m_Letters[25] = 'z'; 

	float startPosX = -460.0f;
	float startPosY = -150.0f;
	float stepX = 45.0f;
	float stepY = 45.0f;
	int columnCount = 6;
	int rowCount = 4;
	int id = 0;
	int currentColumn = 0;
	int currentRow = 0;
	m_pMenu = CCMenu::create();
	for(int i=0;i<m_Letters.size();i++)
	{
		Point pos = Point(startPosX+(currentColumn*stepX),startPosY+(-currentRow*stepY));
		CCMenuItem * button = CCMenuItemImage::create(
			"base.png",
			"fixed.png",
			this,
			menu_selector(CChooseLetterWindow::LetterBtnClick));
		button->setTag(int(m_Letters[i]));
		button->setScale(0.35f);
		button->setPosition(pos);
		LabelTTF * letterLabel = LabelTTF::create("0","helvetica",82);	
		letterLabel->setPosition(button->getContentSize().width/2,button->getContentSize().height/2);
		letterLabel->setColor(Color3B(0,0,0));
		std::string str = "A";
		str[0] = m_Letters[i];
		std::transform(str.begin(), str.end(),str.begin(), ::toupper);
		letterLabel->setString(str);
		button->addChild(letterLabel);
		//letterLabel->setPosition(pos);

		currentColumn++;
		if(currentColumn == columnCount)
		{
			currentColumn = 0;
			currentRow++;
		}
		m_pMenu->addChild(button);
		m_pMenu->setEnabled(false);
	}

	m_Back->addChild(m_pMenu);


	return true;
}
void NodeChildrenMainScene::updateQuantityLabel()
{
    if( quantityOfNodes != lastRenderedCount )
    {
        LabelTTF *infoLabel = (LabelTTF *) getChildByTag(kTagInfoLayer);
        char str[20] = {0};
        sprintf(str, "%u nodes", quantityOfNodes);
        infoLabel->setString(str);

        lastRenderedCount = quantityOfNodes;
    }
}
void SpriteMainScene::updateNodes()
{
    if( quantityNodes != lastRenderedCount )
    {
        LabelTTF *infoLabel = (LabelTTF *) getChildByTag(kTagInfoLayer);
        char str[16] = {0};
        sprintf(str, "%u nodes", quantityNodes);
        infoLabel->setString(str);

        lastRenderedCount = quantityNodes;
    }
}
Пример #8
0
bool Game::onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent)
{
    Vec2 ptouch = pTouch->getLocationInView();
	if (ptouch.x > 250 && ptouch.y > 420) {
       SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
        this->schedule(schedule_selector(Game::exitGame), 0);
        return true;
	}
	
	Vec2 pointcurrent = this->pointOfView(pTouch->getLocationInView());
    
    if (this->isValiableNode(pointcurrent) == false) {
        return false;
    }
	
	if (this->isEmptyNode(pointcurrent)) {
		return false;
	}
	SimpleAudioEngine::getInstance()->playEffect("LinkLiner/choose.wav");
    
	if (this->isSamePoints(pointcurrent, prePoint)) {
		return false;
	}
	
	Sprite *spritecurrent = (Sprite *)this->getChildByTag(TAG_START_SPRITE + this->indexFromPoint(pointcurrent));
    
	spritecurrent->setScale(0.6f);
	
	if (this->isValiableNode(prePoint)) {
		Sprite *spritepre = (Sprite *)this->getChildByTag(TAG_START_SPRITE + this->indexFromPoint(prePoint));
		if (this->canClearTwo(prePoint, pointcurrent)) {
           SimpleAudioEngine::getInstance()->playEffect("LinkLiner/disappear1.wav");
            this->clearNode(prePoint);
            this->clearNode(pointcurrent);
            spritepre->setVisible(false);
            spritecurrent->setVisible(false);
			if (++countCleared >= MAX_CLEARED) {
               SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
               SimpleAudioEngine::getInstance()->playEffect("LinkLiner/win.mp3");
                this->showWin();
			}
			LabelTTF *label = (LabelTTF *)this->getChildByTag(TAG_LABEL_CONNER);
            cocos2d::String *str = String::createWithFormat("进度:%d%%", (int)(countCleared * 100 / MAX_CLEARED));
            label->setString(str->getCString());
		} else {
			spritepre->setScale(0.5);
		}
	}
	
	prePoint = pointcurrent;
    return true;
}
Пример #9
0
void GamePlay::showTime(float timeplay) {
	LabelTTF *currenttime = (LabelTTF*) this->getChildByTag(
			TAG_LABEL_COUNT_TIME);
	int seconds = (int) timeplay % 60;
	int minutes = (int) (timeplay / 60) % 60;
	int hours = (int) timeplay / 3600;
//	if (minutes < 60)
	String* timeString = String::createWithFormat("%02d:%02d", minutes,
			seconds);
//	else
//		timeString = String::createWithFormat("%02d:%02d:%02d", hours, minutes,
//				seconds);
	currenttime->setString(timeString->_string.c_str());
}
Пример #10
0
void TestAsynchronousLoading::dataLoaded(float percent)
{
    LabelTTF *label = (LabelTTF *)getChildByTag(10001);
    if (label)
    {
        char pszPercent[255];
        sprintf(pszPercent, "%s %f", subtitle().c_str(), percent * 100);
        label->setString(pszPercent);
    }

    if (percent >= 1 && backItem && restartItem && nextItem)
    {
        backItem->setEnabled(true);
        restartItem->setEnabled(true);
        nextItem->setEnabled(true);
    }
}
Пример #11
0
void GameLayer::onScoreChanged(int score)
{
	int bestScore = UserDefault::getInstance()->getIntegerForKey("bestScore");

	if (_moveSteps == 10)
	{	
		if (bestScore < score)
		{
			bestScore = score;
			UserDefault::getInstance()->setIntegerForKey("bestScore", score);
			
		}
	}
	LabelTTF* label = (LabelTTF*)getChildByTag(100);
	char scores[50];
	sprintf(scores, "BestScore : %d, Score : %d, Step : %d", bestScore, score, _moveSteps);
	label->setString(scores);
}
TableViewCell* HelloWorld::tableCellAtIndex(cocos2d::extension::TableView *table, ssize_t idx){
    
    TableViewCell *cell = table->dequeueCell();
    LabelTTF *label;
    
    if(cell == NULL){
        cell = TableViewCell::create();
        label = LabelTTF::create();
        label->setTag(2);
        cell->addChild(label);
        label->setFontSize(30);
        label->setAnchorPoint(Point(0,0));
    }
    else {
        label = (LabelTTF*)cell->getChildByTag(2);
    }
    
    label->setString(StringUtils::format("Label %ld",idx));
    
    return cell;
};
Пример #13
0
void TestPerformance::update(float delta)
{
    frames ++;
    times += delta;

    if (frames / times > 58)
    {
        Armature *armature = NULL;
        armature = new Armature();
        armature->init("Knight_f/Knight");
        armature->getAnimation()->playByIndex(0);
        armature->setPosition(50 + armatureCount * 2, 150);
        armature->setScale(0.6f);
        addArmature(armature);
        armature->release();

        char pszCount[255];
        sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount);
        LabelTTF *label = (LabelTTF *)getChildByTag(10001);
        label->setString(pszCount);
    }
}
void HelloWorld::menuEventCallback(cocos2d::Ref* pSender){
    MenuItemLabel* pMenuItem = (MenuItemLabel*)pSender;
    char buf[64];
    int i = pMenuItem->getTag();
    
    sprintf(buf, s_EventMenuItem[i].id.c_str(), ++_indexes[i]);
    LabelTTF* label = (LabelTTF*)pMenuItem->getLabel();
    label->setString(buf);
    switch (i) {
        case CREATE_USER_ID:
            mTDGAaccount = TDCCAccount::setAccount(label->getString().c_str());
            break;
            
        case ADD_LEVEL:
            if (mTDGAaccount) mTDGAaccount->setLevel(_indexes[i]);
            break;
            
        case UPDATE_GAME_SERVER:
            if (mTDGAaccount) mTDGAaccount->setGameServer(label->getString().c_str());
            break;
            
        case UPDATE_USER_NAME:
            if (mTDGAaccount) mTDGAaccount->setAccountName(label->getString().c_str());
            break;
            
        case UPDATE_GENDER:
            if (mTDGAaccount) mTDGAaccount->setGender(mTDGAaccount->kGenderMale);
            break;
            
        case UPDATE_TYPE:
            if (mTDGAaccount) mTDGAaccount->setAccountType(mTDGAaccount->kAccountType1);
            break;
            
        default:
            break;
    }
}
Пример #15
0
void Game::initView()
{
	auto eventListener = EventListenerTouchOneByOne::create();
	eventListener->onTouchBegan = [&](Touch *pTouch, Event*event)
	{
		Vec2 ptouch = pTouch->getLocation();
		if (ptouch.x > 250 && ptouch.y > 420) {
			SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
			this->schedule(schedule_selector(Game::exitGame), 0);
			return true;
		}

		Vec2 pointcurrent = this->pointOfView(pTouch->getLocationInView());

		if (this->isValiableNode(pointcurrent) == false) {
			return false;
		}

		if (this->isEmptyNode(pointcurrent)) {
			return false;
		}
		SimpleAudioEngine::getInstance()->playEffect("LinkLiner/choose.wav");

		if (this->isSamePoints(pointcurrent, prePoint)) {
			return false;
		}

		Sprite *spritecurrent = (Sprite *)this->getChildByTag(TAG_START_SPRITE + this->indexFromPoint(pointcurrent));

		spritecurrent->setScale(0.6);

		if (this->isValiableNode(prePoint)) {
			Sprite *spritepre = (Sprite *)this->getChildByTag(TAG_START_SPRITE + this->indexFromPoint(prePoint));
			if (this->canClearTwo(prePoint, pointcurrent)) {
				SimpleAudioEngine::getInstance()->playEffect("LinkLiner/disappear1.wav");
				this->clearNode(prePoint);
				this->clearNode(pointcurrent);
				spritepre->setVisible(false);
				spritecurrent->setVisible(false);
				if (++countCleared >= MAX_CLEARED) {
					SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
					SimpleAudioEngine::getInstance()->playEffect("LinkLiner/win.mp3");
					this->showWin();
				}
				LabelTTF *label = (LabelTTF *)this->getChildByTag(TAG_LABEL_CONNER);
				cocos2d::String *str = String::createWithFormat("Loading:%d%%", (int)(countCleared * 100 / MAX_CLEARED));
				label->setString(str->getCString());
			}
			else {
				spritepre->setScale(0.5);
			}
		}

		prePoint = pointcurrent;
		return true;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, this);
    Size size = Director::getInstance()->getWinSize();
    
	Sprite *background = Sprite::create("LinkLiner/bg.png");
    background->setPosition(ccp(size.width/2, size.height/2));
    this->addChild(background);
    ;
	for (int y = 0; y < TOTAL_Y; ++y) {
		for (int x = 0; x < TOTAL_X; ++x) {
			int index = y * TOTAL_Y + x;
            if(this->imageFilename(index)){
                Sprite *sprite = Sprite::create(this->imageFilename(index)->getCString());
                sprite->setScale(0.5f);
                sprite->setPosition(ccp(OFFSET_X + (SIZE_W / 2) + SIZE_W * x, OFFSET_Y + (SIZE_H / 2) + SIZE_H * y));
                this->addChild(sprite, 0, (TAG_START_SPRITE + index));
            }
		}
	}
	
	Sprite *button = Sprite::create("LinkLiner/play.png");
    button->setPosition(ccp(size.width - 55, 25));
	this->addChild(button);
	
	LabelTTF *label = LabelTTF::create("进度:0%", "Arial", 20.0);
	label->setPosition(ccp(50, 15));
    this->addChild(label,0,TAG_LABEL_CONNER);
	
	LabelTTF *labelnum1 = LabelTTF::create("1", "Marker Felt", 64.0);
    labelnum1->setPosition(ccp( size.width /2 , size.height/2 ));
	this->addChild(labelnum1);
    
	LabelTTF *labelnum2 = LabelTTF::create("2", "Marker Felt", 64.0);
    labelnum2->setPosition(ccp( size.width /2 , size.height/2 ));
    labelnum2->setVisible(false);
	this->addChild(labelnum2);
    
    LabelTTF *labelnum3 = LabelTTF::create("3", "Marker Felt", 64.0);
    labelnum3->setPosition(ccp( size.width /2 , size.height/2 ));
    labelnum3->setVisible(false);
	this->addChild(labelnum3);
    
    LabelTTF *labelnum4 = LabelTTF::create("Go", "Marker Felt", 64.0);
    labelnum4->setPosition(ccp( size.width /2 , size.height/2 ));
    labelnum4->setVisible(false);
	this->addChild(labelnum4);
    
    void* ac1a = labelnum1->runAction(cocos2d::Show::create());
	void* ac1b = labelnum1->runAction(cocos2d::ScaleBy::create(0.5, 2.0));
    void* ac1c = labelnum1->runAction(cocos2d::Hide::create());
    
    void* ac2a = labelnum2->runAction(cocos2d::Show::create());
	void* ac2b = labelnum2->runAction(cocos2d::ScaleBy::create(0.5, 2.0));
    void* ac2c = labelnum2->runAction(cocos2d::Hide::create());
    
    void* ac3a = labelnum3->runAction(cocos2d::Show::create());
	void* ac3b = labelnum3->runAction(cocos2d::ScaleBy::create(0.5, 2.0));
    void* ac3c = labelnum3->runAction(cocos2d::Hide::create());
    
    
    void* ac4a = labelnum4->runAction(cocos2d::Show::create());
	void* ac4b = labelnum4->runAction(cocos2d::ScaleBy::create(0.5, 2.0));
    void* ac4c = labelnum4->runAction(cocos2d::Hide::create());
    
    labelnum1->runAction(cocos2d::Sequence::create(cocos2d::DelayTime::create(0.5),ac1a,ac1b,ac1c,NULL));
    labelnum2->runAction(cocos2d::Sequence::create(cocos2d::DelayTime::create(0.5),ac2a,ac2b,ac2c,NULL));
    labelnum3->runAction(cocos2d::Sequence::create(cocos2d::DelayTime::create(0.5),ac3a,ac3b,ac3c,NULL));
    labelnum4->runAction(cocos2d::Sequence::create(cocos2d::DelayTime::create(0.5),ac4a,ac4b,ac4c,NULL));
     
}
Пример #16
0
void PlayMenu::updateLifeCountLabel(){
    LabelTTF *lifeCountLabel = (LabelTTF *) this->getChildByTag(KTAG_Life_Count);
    string TotalLifeCount = static_cast<ostringstream*>( &(ostringstream() << GAME_SHARED_HANDLER->getLives()) )->str();
    TotalLifeCount="Life Count " + TotalLifeCount;
    lifeCountLabel->setString(TotalLifeCount.c_str());
}