【问题标题】:Cocos2d-x::CCLabelTTF not add to layerCocos2d-x::CCLabelTTF 不添加到图层
【发布时间】:2014-05-14 12:01:57
【问题描述】:

我想在 CCLayerColor 上添加标签,但我没有得到...

 // on "init" you need to initialize your instance
bool SplashScreen::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayerColor::initWithColor(Colors::GetMainAccentColor4B()) )
    {
        return false;
    }

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

    auto label1 = CCLabelTTF::create("Hello World", "Helvetica", 12,
        CCSizeMake(245, 32), kCCTextAlignmentCenter);
    this->addChild(label1, 1);

    return true;
}

Colors::GetMainAccentColor4B() - 工作正常 - 这是我的课,给我颜色

Screenshot

【问题讨论】:

  • 尝试在addChild 语句之后设置标签的位置。

标签: windows-phone-8 cocos2d-x cocos2d-x-3.0


【解决方案1】:

试试这个

auto label = LabelTTF::create("Hello World", "Helvetica", 100, Size(245, 32), TextHAlignment::CENTER);
label->setPosition(Point(visibleSize.width * 0.5, visibleSize.height * 0.5));
this->addChild(label);

它应该在中心的屏幕上绘制一个标签。不要在 cocos2d-x 3.0 中使用像 CCLabelTTF 这样不推荐使用的方法或类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多