Using SQLite
You can save and load game data easily by using the database in your game. In a smartphone application, the database called SQLite is usually used. SQLite is easy to use. However, you have to set a few things before using it. In this recipe, we will explain how to set up and use SQLite in Cocos2d-x.
Getting ready
Cocos2d-x doesn't have an SQLite library. You have to add SQLite's source code to Cocos2d-x.
You need to download the source code from the site http://sqlite.org/download.html. The latest version at the time of writing this book is version 3.8.10. You can download this version's .zip
file and expand it. Then, you can add the resulting files to your project as shown in the following image:
In this recipe, we will create an original class called SQLiteManager
. So, you have to add the SQLiteManager.h
and SQLiteManager.cpp
files to your project.
Then, if you build for Android, you have to edit proj.android/jni/Android.mk
as follows:
LOCAL_SRC_FILES := hellocpp/main.cpp \ ...