-
Book Overview & Buying
-
Table Of Contents
Cocos2d Cross-Platform Game Development Cookbook - Second Edition - Second Edition
By :
In this section, we will take a look at how to add text to a scene. In Cocos2d, there are two ways in which we can add text: the CCLabelTTF way and the CCLabelBMFont way. We will look at CCLabelBMFont later in the book when we cover Glyph Designer in Chapter 9, Game Tools. For now, we will consider what CCLabels are and how they work.
CCLabelsTTF uses system fonts that are already present on our Mac system. So, additional work is required here. We will just call the name of the font, the text we want to display, and the size of the font, and we are good to go!
Note that there may be cases where the font is installed on your system and it still isn't displayed in the game. This is because Cocos2d includes only some of the system fonts. If you want to add a system font that is not in the list, you need to add it yourself.
Right after adding the background image, we will add the following code:
CCLabelTTF *mainmenuLabel = ...
Change the font size
Change margin width
Change background colour