auto label = Label::create("helloworld","Arial",50);//创建label label->setPosition(visibleSize.width / 2,visibleSize.height / 2); this->addChild(label); auto label2 = Label::createWithTTF("hello cocos","fonts/Marker Felt.ttf",50); label2->setPosition(visibleSize.width / 2,visibleSize.height / 4); this->addChild(label2); auto label3 = Label::createWithBMFont("markerFelt.fnt","hello everybody"); label3->setPosition(visibleSize.width / 4,visibleSize.height / 2); this->addChild(label3); auto label4 = Label::createWithSystemFont("systemtest","arial",24); label4->setPosition(visibleSize.width / 4,visibleSize.height / 4); this->addChild(label4); auto label5 = Label::createWithCharMap("tuffy_bold_italic-charmap.plist"); label5->setString("charmaptest"); label5->setPosition(visibleSize.width / 2,visibleSize.height*0.75); this->addChild(label5);
label的创建和精灵一样,调用静态方法进行创建,然后设置位置,并添加到层中。
label->setAnchorPoint(Point(0,0));//设置锚点 label2->setColor(Color3B::GREEN);//设置颜色 label3->setRotation(var);//设置旋转角度 label4->setScale(2.0f);//放大缩小 label5->setString("testcharmap");//修改内容
label->setAlignment(TextHAlignment::CENTER);//对齐方法 label2->enableOutline(Color4B::GREEN,3);//发光 label3->setAdditionalKerning(20);//设置字间距 label4->enableShadow();//设置阴影 label5->setLineHeight(10);//设置行高
原文链接:/cocos2dx/344526.html