O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating system fonts

You can create the labels that use the fonts of the host operating system; therefore, you would not be required to provide a font file. It is recommended that you use this kind of label only for testing purposes, since it would decrease the framework's flexibility because the selected font may not be available on the user's Android operating system version.

Just for the sake of testing, below our current text, we will add the following label in the init method of the GameOverScene.cpp implementation file:

auto label2 = Label::createWithSystemFont("Your score is", "Arial", 48);
label2->setPosition(origin.x + visibleSize.width/2,origin.y + visibleSize.height /2.5);
this->addChild(label2, 1);

This code yields the following result: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required