コード例 #1
0
ファイル: CCLabel.cpp プロジェクト: 4an70m/Cocos2dxTest
void Label::createSpriteWithFontDefinition()
{
    _currentLabelType = LabelType::STRING_TEXTURE;

    auto texture = new Texture2D;
    texture->initWithString(_originalUTF8String.c_str(),_fontDefinition);

    _textSprite = Sprite::createWithTexture(texture);
    _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
    this->setContentSize(_textSprite->getContentSize());
    texture->release();
    if (_blendFuncDirty)
    {
        _textSprite->setBlendFunc(_blendFunc);
    }

    Node::addChild(_textSprite,0,Node::INVALID_TAG);

    _textSprite->updateDisplayedColor(_displayedColor);
    _textSprite->updateDisplayedOpacity(_displayedOpacity);
}
コード例 #2
0
// LabelBMFontCrashTest
void LabelBMFontCrashTest::onEnter()
{
    AtlasDemo::onEnter();
    
    auto winSize = Director::getInstance()->getWinSize();
    //Create a label and add it
    auto label1 = new LabelBMFont();
    label1->initWithString("test", "fonts/bitmapFontTest2.fnt");
    this->addChild(label1);
    // Visit will call draw where the function "ccGLBindVAO(m_uVAOname);" will be invoked.
    label1->visit();
    
    // Remove this label
    label1->removeFromParentAndCleanup(true);
    label1->release();
    
    // Create a new label and add it (then crashes)
    auto label2 = LabelBMFont::create("test 2", "fonts/bitmapFontTest.fnt");
    label2->setPosition(Point(winSize.width/2, winSize.height/2));
    this->addChild(label2);
}
コード例 #3
0
ファイル: CCLabel.cpp プロジェクト: khanhbui/ThreeDots
void Label::createSpriteWithFontDefinition()
{
    _currentLabelType = LabelType::STRING_TEXTURE;
    auto texture = new Texture2D;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
    if (_fontDefinition._shadow._shadowEnabled || _fontDefinition._stroke._strokeEnabled)
    {
        CCLOGERROR("Currently only supported on iOS and Android!");
    }
    _fontDefinition._shadow._shadowEnabled = false;
    _fontDefinition._stroke._strokeEnabled = false;
#endif
    texture->initWithString(_originalUTF8String.c_str(),_fontDefinition);

    _textSprite = Sprite::createWithTexture(texture);
    _textSprite->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
    this->setContentSize(_textSprite->getContentSize());
    texture->release();

    Node::addChild(_textSprite,0,Node::INVALID_TAG);
}
コード例 #4
0
ファイル: CCLabel.cpp プロジェクト: CienProject2016/VESS
void Label::createShadowSpriteForSystemFont(const FontDefinition& fontDef)
{
    if (!fontDef._stroke._strokeEnabled && fontDef._fontFillColor == _shadowColor3B
        && (fontDef._fontAlpha == _shadowOpacity))
    {
        _shadowNode = Sprite::createWithTexture(_textSprite->getTexture());
    }
    else
    {
        FontDefinition shadowFontDefinition = fontDef;
        shadowFontDefinition._fontFillColor.r = _shadowColor3B.r;
        shadowFontDefinition._fontFillColor.g = _shadowColor3B.g;
        shadowFontDefinition._fontFillColor.b = _shadowColor3B.b;
        shadowFontDefinition._fontAlpha = _shadowOpacity;

        shadowFontDefinition._stroke._strokeColor = shadowFontDefinition._fontFillColor;
        shadowFontDefinition._stroke._strokeAlpha = shadowFontDefinition._fontAlpha;

        auto texture = new (std::nothrow) Texture2D;
        texture->initWithString(_utf8Text.c_str(), shadowFontDefinition);
        _shadowNode = Sprite::createWithTexture(texture);
        texture->release();
    }

    if (_shadowNode)
    {
        if (_blendFuncDirty)
        {
            _shadowNode->setBlendFunc(_blendFunc);
        }
        _shadowNode->setCameraMask(getCameraMask());
        _shadowNode->setGlobalZOrder(getGlobalZOrder());
        _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
        _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);

        _shadowNode->retain();
        _shadowNode->updateDisplayedColor(_displayedColor);
        _shadowNode->updateDisplayedOpacity(_displayedOpacity);
    }
}
コード例 #5
0
ファイル: CCLabel.cpp プロジェクト: wade0317/Calc
void Label::createSpriteForSystemFont(const FontDefinition& fontDef)
{
    _currentLabelType = LabelType::STRING_TEXTURE;

    auto texture = new (std::nothrow) Texture2D;
    texture->initWithString(_utf8Text.c_str(), fontDef);

    _textSprite = Sprite::createWithTexture(texture);
    //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label
    _textSprite->setCameraMask(getCameraMask());
    _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
    this->setContentSize(_textSprite->getContentSize());
    texture->release();
    if (_blendFuncDirty)
    {
        _textSprite->setBlendFunc(_blendFunc);
    }

    _textSprite->retain();
    _textSprite->updateDisplayedColor(_displayedColor);
    _textSprite->updateDisplayedOpacity(_displayedOpacity);
}
コード例 #6
0
ファイル: CCLabel.cpp プロジェクト: Ratel13/Cocos2dGame-v3.7
void Label::createShadowSpriteForSystemFont()
{
    if (!_fontDefinition._stroke._strokeEnabled && _fontDefinition._fontFillColor == _shadowColor3B
        && (_fontDefinition._fontAlpha == _shadowOpacity))
    {
        _shadowNode = Sprite::createWithTexture(_textSprite->getTexture());
    }
    else
    {
        auto shadowFontDefinition = _fontDefinition;
        shadowFontDefinition._fontFillColor.r = _shadowColor3B.r;
        shadowFontDefinition._fontFillColor.g = _shadowColor3B.g;
        shadowFontDefinition._fontFillColor.b = _shadowColor3B.b;
        shadowFontDefinition._fontAlpha = _shadowOpacity;

        shadowFontDefinition._stroke._strokeColor = shadowFontDefinition._fontFillColor;
        shadowFontDefinition._stroke._strokeAlpha = shadowFontDefinition._fontAlpha;

        auto texture = new (std::nothrow) Texture2D;
        texture->initWithString(_originalUTF8String.c_str(), shadowFontDefinition);
        _shadowNode = Sprite::createWithTexture(texture);
        texture->release();
    }

    if (_shadowNode)
    {
        if (_blendFuncDirty)
        {
            _shadowNode->setBlendFunc(_blendFunc);
        }
        _shadowNode->setCameraMask(getCameraMask());
        _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
        _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
        Node::addChild(_shadowNode, 0, Node::INVALID_TAG);

        _shadowNode->updateDisplayedColor(_displayedColor);
        _shadowNode->updateDisplayedOpacity(_displayedOpacity);
    }
}
コード例 #7
0
ファイル: CCLabel.cpp プロジェクト: adroitly/boom
void Label::createSpriteWithFontDefinition()
{
    _currentLabelType = LabelType::STRING_TEXTURE;

    auto texture = new (std::nothrow) Texture2D;
    texture->initWithString(_originalUTF8String.c_str(),_fontDefinition);

    _textSprite = Sprite::createWithTexture(texture);
    //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label
    _textSprite->setCameraMask(getCameraMask());
    _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
    this->setContentSize(_textSprite->getContentSize());
    texture->release();
    if (_blendFuncDirty)
    {
        _textSprite->setBlendFunc(_blendFunc);
    }

    Node::addChild(_textSprite,0,Node::INVALID_TAG);

    _textSprite->updateDisplayedColor(_displayedColor);
    _textSprite->updateDisplayedOpacity(_displayedOpacity);
}
コード例 #8
0
ファイル: SchedulerTest.cpp プロジェクト: AomXD/workspace
//------------------------------------------------------------------
//
// SchedulerUpdate
//
//------------------------------------------------------------------
void SchedulerUpdate::onEnter()
{
    SchedulerTestLayer::onEnter();

    auto d = new (std::nothrow) TestNode();
    d->initWithString("---", 50);
    addChild(d);
    d->release();

    auto b = new (std::nothrow) TestNode();
    b->initWithString("3rd", 0);
    addChild(b);
    b->release();

    auto a = new (std::nothrow) TestNode();
    a->initWithString("1st", -10);
    addChild(a);
    a->release();

    auto c = new (std::nothrow) TestNode();
    c->initWithString("4th", 10);
    addChild(c);
    c->release();

    auto e = new (std::nothrow) TestNode();
    e->initWithString("5th", 20);
    addChild(e);
    e->release();

    auto f = new (std::nothrow) TestNode();
    f->initWithString("2nd", -5);
    addChild(f);
    f->release();

    schedule(CC_SCHEDULE_SELECTOR(SchedulerUpdate::removeUpdates), 4.0f);
}
コード例 #9
0
ファイル: SchedulerTest.cpp プロジェクト: AppleJDay/cocos2d-x
//------------------------------------------------------------------
//
// SchedulerUpdate
//
//------------------------------------------------------------------
void SchedulerUpdate::onEnter()
{
    SchedulerTestLayer::onEnter();

    auto d = new TestNode();
    d->initWithString("---", 50);
    addChild(d);
    d->release();

    auto b = new TestNode();
    b->initWithString("3rd", 0);
    addChild(b);
    b->release();

    auto a = new TestNode();
    a->initWithString("1st", -10);
    addChild(a);
    a->release();

    auto c = new TestNode();
    c->initWithString("4th", 10);
    addChild(c);
    c->release();

    auto e = new TestNode();
    e->initWithString("5th", 20);
    addChild(e);
    e->release();

    auto f = new TestNode();
    f->initWithString("2nd", -5);
    addChild(f);
    f->release();

    schedule(schedule_selector(SchedulerUpdate::removeUpdates), 4.0f);
}
コード例 #10
0
ファイル: CCLabel.cpp プロジェクト: Ratel13/Cocos2dGame-v3.7
void Label::createSpriteForSystemFont()
{
    _currentLabelType = LabelType::STRING_TEXTURE;

    if (!_compatibleMode)
    {
        _fontDefinition._fontName = _systemFont;
        _fontDefinition._fontSize = _systemFontSize;

        _fontDefinition._alignment = _hAlignment;
        _fontDefinition._vertAlignment = _vAlignment;

        _fontDefinition._dimensions.width = _labelWidth;
        _fontDefinition._dimensions.height = _labelHeight;

        _fontDefinition._fontFillColor.r = _textColor.r;
        _fontDefinition._fontFillColor.g = _textColor.g;
        _fontDefinition._fontFillColor.b = _textColor.b;
        _fontDefinition._fontAlpha = _textColor.a;

        _fontDefinition._shadow._shadowEnabled = false;

        if (_currLabelEffect == LabelEffect::OUTLINE && _outlineSize > 0)
        {
            _fontDefinition._stroke._strokeEnabled = true;
            _fontDefinition._stroke._strokeSize = _outlineSize;
            _fontDefinition._stroke._strokeColor.r = _effectColor.r;
            _fontDefinition._stroke._strokeColor.g = _effectColor.g;
            _fontDefinition._stroke._strokeColor.b = _effectColor.b;
            _fontDefinition._stroke._strokeAlpha = _effectColor.a;
        }
        else
        {
            _fontDefinition._stroke._strokeEnabled = false;
        }

#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
        if (_fontDefinition._stroke._strokeEnabled)
        {
            CCLOGERROR("Currently only supported on iOS and Android!");
        }
        _fontDefinition._stroke._strokeEnabled = false;
#endif
    }

    auto texture = new (std::nothrow) Texture2D;
    texture->initWithString(_originalUTF8String.c_str(), _fontDefinition);

    _textSprite = Sprite::createWithTexture(texture);
    //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label
    _textSprite->setCameraMask(getCameraMask());
    _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
    this->setContentSize(_textSprite->getContentSize());
    texture->release();
    if (_blendFuncDirty)
    {
        _textSprite->setBlendFunc(_blendFunc);
    }

    Node::addChild(_textSprite, 0, Node::INVALID_TAG);

    _textSprite->updateDisplayedColor(_displayedColor);
    _textSprite->updateDisplayedOpacity(_displayedOpacity);
}
コード例 #11
0
bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap)
{
    Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(charMapFile);
	return initWithString(string, texture, itemWidth, itemHeight, startCharMap);
}
コード例 #12
0
bool CCLabelAtlas::initWithString(const char *string, const char *charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
{
    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(charMapFile);
	return initWithString(string, texture, itemWidth, itemHeight, startCharMap);
}
コード例 #13
0
ファイル: UILabelAtlas.cpp プロジェクト: duongbadu/FightGame
void UICCLabelAtlas::setProperty(const char *string, Texture2D *texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
{
    initWithString(string, texture, itemWidth, itemHeight, startCharMap);
}
コード例 #14
0
ファイル: UILabelAtlas.cpp プロジェクト: Srinoid/cocos2d-x
void UICCLabelAtlas::setProperty(const std::string& string, const std::string& charMapFile, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
{
    initWithString(string.c_str(), charMapFile.c_str(), itemWidth, itemHeight, startCharMap);
}
コード例 #15
0
ファイル: UILabelAtlas.cpp プロジェクト: Srinoid/cocos2d-x
void UICCLabelAtlas::setProperty(const std::string& string, CCTexture2D *texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
{
    initWithString(string.c_str(), texture, itemWidth, itemHeight, startCharMap);
}
コード例 #16
0
ファイル: CCMenuItem.cpp プロジェクト: Ratel13/WarriorQuest
// XXX: deprecated
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector)
{
	_target = target;
	CC_SAFE_RETAIN(_target);
	return initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, std::bind(selector,target, std::placeholders::_1) );
}
コード例 #17
0
// FIXME:: deprecated
bool MenuItemFont::initWithString(const std::string& value, Ref* target, SEL_MenuHandler selector)
{
    CCASSERT( !value.empty(), "Value length must be greater than 0");

    return initWithString(value, std::bind(selector,target, std::placeholders::_1) );
}