Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the maximum texture size


The maximum texture size that can be used is different for each device. In particular, when you use the texture atlas, you should be careful. That's why a texture atlas that has a lot of images is too large in size. You can't use a texture that is over the maximum size. If you use it, your game will crash. In this recipe, you can get the maximum texture size.

How to do it...

You can get the max texture size easily by using the following code:

auto config = Configuration::getInstance();
int texutureSize = config->getMaxTextureSize();
CCLOG("max texture size = %d", texutureSize);

How it works...

The Configuration class is a singleton class. This class has some OpenGL variables. OpenGL is a multiplatform API for rendering 2D and 3D vector graphics. It is pretty difficult to use. Cocos2d-x wraps it and makes it easy to use. OpenGL has a lot of information for graphics. The max texture size is one of the variables providing this information. You can get the max...