Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The easy way – CCLabelTTF


We've already used the CCLabelTTF class to display the text on the screen. It was pretty easy, wasn't it? We only specified the font name, the size, and the text itself, and here it was displayed on the screen. But there is a price for that simplicity.

Unfortunately, it is not that simple to draw text using OpenGL (which is used by Cocos2D internally). There is simply no built-in functionality that takes the text and renders it on the screen. We have to render the text manually by drawing each letter separately in its place using primitives (lines and triangles), and doing this for every frame badly affects performance.

To optimize this, Cocos2D renders the text only once, places the result into the texture, and then displays this texture. In other words, it creates an image in memory with this text on the fly, and then it easily renders this image using OpenGL.

This helps to optimize performance, but if we change any property of the label (font size, alignment, color...