Beispiel #1
0
Label* Label::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment /* = TextHAlignment::CENTER */, int maxLineWidth /* = 0 */)
{
    auto ret = new Label(nullptr,alignment);

    if (!ret)
    {
        return nullptr;
    }

    do 
    {
        if( FileUtils::getInstance()->isFileExist(ttfConfig.fontFilePath) && ret->setTTFConfig(ttfConfig))
        {
            break;
        }

        FontDefinition fontDef;
        fontDef._fontName = ttfConfig.fontFilePath;
        fontDef._fontSize = ttfConfig.fontSize;
        fontDef._dimensions = Size::ZERO;
        fontDef._alignment = alignment;
        fontDef._vertAlignment = TextVAlignment::TOP;
        ret->setFontDefinition(fontDef);
    } while (0);

    ret->setMaxLineWidth(maxLineWidth);
    ret->setString(text);
    ret->autorelease();

    return ret;
}
Beispiel #2
0
LabelRPG* LabelRPG::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment /* = TextHAlignment::CENTER */, int maxLineWidth /* = 0 */)
{
    auto ret = new LabelRPG(nullptr,alignment);

    if (ret && FileUtils::getInstance()->isFileExist(ttfConfig.fontFilePath) && ret->setTTFConfig(ttfConfig))
    {
        ret->setMaxLineWidth(maxLineWidth);
        ret->setString(text);
        ret->autorelease();

        return ret;
    }

    delete ret;
    return nullptr;
}
Beispiel #3
0
Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment /* = TextHAlignment::LEFT */, int maxLineWidth /* = 0 */, const Vec2& imageOffset /* = Vec2::ZERO */)
{
    auto ret = new (std::nothrow) Label(nullptr,alignment);

    if (ret && ret->setBMFontFilePath(bmfontFilePath,imageOffset))
    {
        ret->setMaxLineWidth(maxLineWidth);
        ret->setString(text);
        ret->autorelease();

        return ret;
    }
    
    delete ret;
    return nullptr;
}
Beispiel #4
0
bool LmLayer::init()
{

	//use to place elements
	Size l_oVisibleSize = Director::getInstance()->getVisibleSize();
	Point l_oOrigin = Director::getInstance()->getVisibleOrigin();

	/*
	 * CENTER = 0
	 * TOP LEFT = 1
	 * TOP RIGHT = 2
	 * BOTTOM LEFT = 3
	 * BOTTOM RIGHT = 4
	 */

	//we add sprites
	for (std::vector<std::pair<std::string, int>>::iterator it =
			m_aImages.begin(); it != m_aImages.end(); ++it)
	{
		auto l_oSprite = Sprite::create(it->first);
		switch (it->second)
		{

		//center
		case 0:
			l_oSprite->setPosition(l_oVisibleSize.width / 2 + l_oOrigin.x,
					l_oVisibleSize.height / 2 + l_oOrigin.y);
			break;

			//top left
		case 1:
			l_oSprite->setAnchorPoint(Vec2(0, 1));
			l_oSprite->setPosition(l_oOrigin.x,
					l_oVisibleSize.height + l_oOrigin.y);
			break;

			//top right
		case 2:
			l_oSprite->setAnchorPoint(Vec2(1, 1));
			l_oSprite->setPosition(l_oVisibleSize.width + l_oOrigin.x,
					l_oVisibleSize.height + l_oOrigin.y);
			break;

			//bottom left
		case 3:
			l_oSprite->setAnchorPoint(Vec2(0, 0));
			l_oSprite->setPosition(l_oOrigin.x, +l_oOrigin.y);
			break;

			//bottom right
		case 4:
			l_oSprite->setAnchorPoint(Vec2(1, 0));
			l_oSprite->setPosition(l_oVisibleSize.width + l_oOrigin.x,
					+l_oOrigin.y);
			break;

		default:
			break;
		}
		addChild(l_oSprite, 0);
	}

	//we preload the sound
	CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic(
			m_sSoundURL.c_str());

	//we add text to the center of the screen
	auto l_pLabel = Label::createWithTTF(m_sText,
			"Fonts/JosefinSans-Regular.ttf", m_fFontSize);
	l_pLabel->setPosition(l_oVisibleSize.width * m_fWidthPercent,
			l_oVisibleSize.height * m_fHeightPercent);
	l_pLabel->setColor(m_oColorText);
	l_pLabel->setAlignment(TextHAlignment::CENTER);
	l_pLabel->setMaxLineWidth(l_oVisibleSize.width * m_fSizePercent);
	addChild(l_pLabel);

	return true;
}
Beispiel #5
0
bool HelloWorld::init()
{

	if ( !Layer::init() )
	{
		return false;
	}

	CReadFile::getInstance()->init();

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto closeItem = MenuItemImage::create(
		"picture/blue1_menu.png",
		"picture/blue2_menu.png" 
		, CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
	closeItem->setScale(0.3f);
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2-310 ,
		origin.y + closeItem->getContentSize().height/2+160));

	auto closeItem1 = MenuItemImage::create(
		"picture/blue1_menu.png",
		"picture/blue2_menu.png",
		CC_CALLBACK_1(HelloWorld::menuCloseCallback1, this));

	closeItem1->setScale(0.5f);

	closeItem1->setPosition(Vec2(origin.x + visibleSize.width - closeItem1->getContentSize().width/2-310 ,
		origin.y + closeItem1->getContentSize().height/2+330));

	auto SetMenu = MenuItemImage::create(
		"picture/shezhi2_cover.png",
		"picture/shezhi1_cover.png",
		CC_CALLBACK_1(HelloWorld::menuCloseCallback3, this));
	SetMenu->setScale(0.8f);

	SetMenu->setPosition(Vec2(origin.x + visibleSize.width - SetMenu->getContentSize().width/2-390 ,
		origin.y + SetMenu->getContentSize().height/2+260));

	auto menu = Menu::create(closeItem,closeItem1,SetMenu, NULL);
	menu->setPosition(Vec2::ZERO);		
	this->addChild(menu, 1);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
	auto label = Label::createWithTTF(Tools::Unicode2Utf8(L"开始游戏"), "fonts/msyh.ttc", 24);
#else
	auto label = Label::createWithTTF("开始游戏", "fonts/msyh.ttc", 24);
#endif
	label->setPosition(Vec2(closeItem1->getPositionX(), closeItem1->getPositionY()));
	label->setScale(0.8f);
	this->addChild(label, 1);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
	auto label1 = Label::createWithTTF(Tools::Unicode2Utf8(L"退出"), "fonts/msyh.ttc", 24);
#else
	auto label1 = Label::createWithTTF("退出", "fonts/msyh.ttc", 24);
#endif
	label1->setPosition(Vec2(closeItem->getPositionX(), closeItem->getPositionY()));
	label1->setScale(0.8f);
	this->addChild(label1,1);

	auto sprite = Sprite::create("picture/shumabaobei.jpg");

	Size sprSize = sprite->getContentSize();

	sprite->setScaleX(visibleSize.width/sprSize.width);
	sprite->setScaleY(visibleSize.height/sprSize.height);
	sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
	this->addChild(sprite, 0);	

	auto logo = Sprite::create("picture/logo.png");
	Size logoSize = logo->getContentSize();

	auto spark = Sprite::create("picture/spark.png");
	spark->setPosition(-logoSize.width,0);
	auto clippingNode = ClippingNode::create();
	clippingNode->setPosition(500,560);
	this->addChild(clippingNode);
	clippingNode->setAlphaThreshold(0.05f);
	clippingNode->setContentSize(logoSize);

	clippingNode->setStencil(logo);
	clippingNode->addChild(logo,1);
	clippingNode->addChild(spark,2);

	auto moveAction = MoveTo::create(2.0f,Vec2(logoSize.width,0));
	auto moveBackAction = MoveTo::create(2.0f,Vec2(-logoSize.width,0));
	spark->runAction(RepeatForever::create(Sequence::create(moveAction,moveBackAction,NULL)));
	if (CReadFile::getInstance()->getshuomingkg())
	{
		CReadFile::getInstance()->setshuomingkg(false);
		CSound::getInstance()->playBG("Butter-Fly.mp3",CSound::getInstance()->getIsPlay());
		CSound::getInstance()->setIsPlay(true);


		auto shuominglayer = LayerColor::create(Color4B(120,120,120,200));
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
		auto wenzi = Label::createWithTTF(Tools::Unicode2Utf8(L"欢迎来到宝库设计的数码宝贝记忆消除游戏"),"fonts/msyh.ttc", 28);
#else
		auto wenzi = Label::createWithTTF("欢迎来到宝库设计的数码宝贝记忆消除游戏","fonts/msyh.ttc", 28);
#endif
		wenzi->setMaxLineWidth(460);
		wenzi->setLineBreakWithoutSpace(true);
		wenzi->setPosition(480,520);
		wenzi->setColor(ccc3(0,0,0));
		shuominglayer->runAction(FadeOut::create(5));
		wenzi->runAction(FadeOut::create(3));
		shuominglayer->addChild(wenzi,2);
		this->addChild(shuominglayer,2);
	}
	return true;
}