如何在全局类(helloworld.h)中使用cocos2d-x v3.2声明标签? [英] how to declare label in global class (helloworld.h) with cocos2d-x v3.2?

查看:213
本文介绍了如何在全局类(helloworld.h)中使用cocos2d-x v3.2声明标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cocos2d-x v3.2(c ++)创建一个二维平台游戏,我使用的是标签。

I'm creating a 2d platform game with cocos2d-x v3.2 (c++) and i'm using label.

cocos2d-x v3.0 c ++)
声明为 cocos2d :: LabelTTF * currentScore;

cocos2d-x v3.0 (c++) declared like cocos2d::LabelTTF* currentScore;

cocos2d-x v2.2.2 c ++)
声明为 cocos2d :: CCLabelTTF * currentScore;

cocos2d-x v2.2.2 (c++) declared like cocos2d::CCLabelTTF* currentScore;

cocos2d-x v3.2 c ++)
如何在全局类(helloworld.h)中声明标签
i尝试像

cocos2d-x v3.2(c++) how to declare label in global class(helloworld.h) i have try like

HelloWorld.h

HelloWorld.h

class HelloWorld : public cocos2d::LayerColor

{
public:
  virtual bool init();
cocos2d::LabelTTF* currentScore;   //semantic issue(LabelTTF deprecared)
};

    #endif

HelloWorld.cpp

HelloWorld.cpp

bool HelloWorld::init()
{
currentScore = LabelTTF::create("", "Arial", 40);  //semantic issue(LabelTTF deprecared)

    // position the label on the center of the screen
    currentScore->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - currentScore->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(currentScore, 1);

    char buffer[10];
    sprintf(buffer, "%04i",0);
    currentScore->setString(std::string(buffer));
}

再次尝试

HelloWorld.cpp

HelloWorld.cpp

 bool HelloWorld::init()
    {

    Auto currentScore = LabelTTF::create("", "Arial", 40);
    //position the label on the center of the screen
        currentScore->setPosition(Vec2(origin.x + visibleSize.width/2,
                                origin.y + visibleSize.height - currentScore->getContentSize().height));

        // add the label as a child to this layer
        this->addChild(currentScore, 1);
    }
  #endif

。在全局类(HelloWorld.h)中声明

it working but can't "Auto currentScore;" declared in global class(HelloWorld.h)

推荐答案

在.h文件中

Label *autolabel4;

在.cpp中

// autolabel4 = Label :: create();无法提高标签大小和大小

// autolabel4 = Label::create(); can't improve label size and fount

autolabel4 = Label::createWithSystemFont("hello","Arial.ttf",40);
  autolabel4->setString("name isss :");
  autolabel4->setColor(Color3B(23,33,44));
  autolabel4->setPosition(Point(origin.x+ visibleSize.width/2,
                              origin.y + visibleSize.height - 400));
      this->addChild(autolabel4, 1);

这篇关于如何在全局类(helloworld.h)中使用cocos2d-x v3.2声明标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆