Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cocos2d-x by example (update)

You're reading from   Cocos2d-x by example (update) Unleash your inner creativity with the popular Cocos2d-x framework and learn how to build great cross-platform 2D games with this Cocos2dx tutorial

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781785288852
Length 270 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Roger Engelbert Roger Engelbert
Author Profile Icon Roger Engelbert
Roger Engelbert
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Installing Cocos2d-x FREE CHAPTER 2. You Plus C++ Plus Cocos2d-x 3. Your First Game – Air Hockey 4. Fun with Sprites – Sky Defense 5. On the Line – Rocket Through 6. Quick and Easy Sprite – Victorian Rush Hour 7. Adding the Looks – Victorian Rush Hour 8. Getting Physical – Box2D 9. On the Level – Eskimo 10. Introducing Lua! A. Vector Calculations with Cocos2d-x B. Pop Quiz Answers Index

Time for action – creating an application

Open Terminal again and follow these easy steps:

  1. You should have the path to the Cocos2d-x console already added to your system. You can test this by using the cocos command inside Terminal. In order to create a new project called HelloWorld, using C++ as its primary language and save it on your desktop, you need to run the following command, replacing YOUR_BUNDLE_INDETIFIER with a package name of your choice, and replacing PATH_TO_YOUR_PROJECT with the path to wherever you wish to save your project:
    cocos new HelloWorld -p YOUR_BUNDLE_IDENTIFIER -l cpp -d PATH_TO_YOUR_PROJECT
    
  2. As an example, in my machine this is the line I typed:
    cocos new HelloWorld -p com.rengelbert.HelloWorld -l cpp -d /Users/rengelbert/Desktop/HelloWorld
    

    And hit Enter. If you choose not to give a directory parameter (-d), the Cocos console will save the project inside the Cocos2d-x folder.

  3. Now you can go to your desktop, or wherever you chose to save your project, and navigate to the folder proj.ios_mac inside the HelloWorld project. Inside that folder you'll find the Xcode project file. Once you open the project inside Xcode, you can click the Run button and you're done.
    Time for action – creating an application

Note

When you run a cocos2d-x application in Xcode, it is quite common for the program to post some warnings regarding your code, or most likely, the frameworks. These will mostly reference deprecated methods or statements that do not precisely follow more recent and stricter rules of the current SDK. But that's okay. These warnings, though certainly annoying, can be ignored.

What just happened?

You created your first Cocos2d-x application. The parameters used on the command line are:

  • -p for package or bundle identifier
  • -l for language, and here, you have the option cpp, lua, or JavaScript

Now let's run this app in Android.

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You have been reading a chapter from
Cocos2d-x by example (update)
Published in: Mar 2015
Publisher:
ISBN-13: 9781785288852
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime