Thẻ

, , ,

1. Label

Label BMFont

auto myLabel = Label::createWithBMFont("bitmapRed.fnt", "Your Text");

Label TTF

auto myLabel = Label::createWithTTF("Your Text", "Marker Felt.ttf", 24);

Sử dụng config

// create a TTFConfig files for labels to share
TTFConfig labelConfig;
labelConfig.fontFilePath = "myFont.ttf";
labelConfig.fontSize = 16;
labelConfig.glyphs = GlyphCollection::DYNAMIC;
labelConfig.outlineSize = 0;
labelConfig.customGlyphs = nullptr;
labelConfig.distanceFieldEnabled = false;

// create a TTF Label from the TTFConfig file.
auto myLabel = Label::createWithTTF(labelConfig, "My Label Text");

Label SystemFont
auto myLabel = Label::createWithSystemFont("My Label Text", "Arial", 16);

Label Effects

// shadow effect is supported by all Label types
myLabel->enableShadow();
// outline effect is TTF only, specify the outline color desired
myLabel->enableOutline(Color4B::WHITE, 1));
// glow effect is TTF only, specify the glow color desired.
myLabel->enableGlow(Color4B::YELLOW);

Button

Thêm thư viện: #include “ui\CocosGUI.h”
và namespace: using namespace ui;

auto button = Button::create("test1.png", "test2.png", "test1.png");
button->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
button->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type){
switch (type)
	{
	case ui::Widget::TouchEventType::BEGAN:
		break;
	case ui::Widget::TouchEventType::ENDED:
		std::cout << "Button 1 clicked" << std::endl;
		break;
	default:
		break;
	}
});
this->addChild(button);
Advertisements