It has been difficult for developers new to cocos2d-x to learn this game framework but a new book just released will make it much easier.
The book, “Cocos2d-X By Example Beginner’s Guide”, provides an entertaining way of learning to develop cross platform games using cocos2d-x.
There are several game examples, Air Hockey, Sky Defense, Rocket Through, Victorian Rush Hour, and Eskimo to demonstrate all the capabilities of cocos2d-x with special attention to the physics engine Box2D. The Appendix provides additional reference information on Vector calculations that help in rotating objects and controlling angular base speeds.
The material is presented well and even provides an overview of C++ as the book goes along so it is perfect for the beginner that wants to learn to make games on multiple platforms (iOS, Android, Blackberry, etc) but also provides in depth information that even the advanced cocos2d-x programmer will appreciate.
If you sign up on the PACKT pub website you will be sent special offers, sometimes up to 60% off their Ebooks. You can also find this book on Amazon and many other places including the link below directly from the publisher.
Buy it now from: http://www.packtpub.com/cocos2d-x-by-example/book
The author of the book also has a great blog with additional tutorials where the algorithms are shared for many common game task using various languages and frameworks, visit it at: http://rengelbert.com/blog/category/tutorials/
A new book that will help you develop cross platform mobile applications was recently released by PACKT Publishing. The book provides all the information you need to get started in developing for android, iPhone, blackberry, and many more platforms.
The most recent release of cocos2d-x has added support for Marmalade so if you plan on writing 2D games for iPhone, Android, Blackberry or any other smartphone (or even LG TV’s) then you should get this book and download the latest cocos2d-x and get started on developing your app.
There is an increasing number of very good tutorials on game development using various game engines. The one shown below is exceptionally well done. Although targeted at iOS development it is easily extended to Android and other platforms using cocos2d-x as shown below with the game running on the Android Kindle Fire.
Angry Ninjas Starter Kit: An Easy to Customize XCode Project PLUS High Definition Video Documentation
To get the cocos2d-x C++ version also please Buy Now.
CartoonSmart offers top line tutorials for various game engines. The one discussed here is the “Angry Ninjas Starter Kit”. We purchased this to review the quality of the tutorials and were very surprised at how much details the tutorial covered.
This Angry Birds type of game goes through all the details to provide a basis for a physics game that is similar to the Angry Birds series. The videos describe in detail on how to customize each parameter for YOUR game. Check out the details of the tutorial here.
Angry Ninjas Starter Kit Marketing info from CartoonSmart:
Sling shot games are quite popular in the App Store aren’t they? Well why not ride that wave and create your own popular app. This template is ready for you to make a great game out of it. All that’s required is a bit of time on your part to build some fantastic levels and add your own artistic twist. We’ve done the hard part. Now you get to do the fun part!
Like all our iOS Starter Kits the project files are included with video guides (accessible online or offline) covering every detail of modifying the app for yourself.
Some Basics about the App Template:
- Runs at 60fps on the iPhone 4, iPhone3GS, iPod Touch and iPad.
- Supports high resolution images for the Retina Display iPhone.
- Preference settings for the iPad or iPhone (for example, you can change things like the stack location, screen pan speed, throw power of the sling shot, etc. by changing simple variables)
- Uses Box2D, an advanced physics engine for realistic collisions (the same as another well-known sling shot game) We like the physics as they are, but you are welcome to toy with gravity, the accelerometer, or any other property to drastically change the game.
- Supports as many levels as you want to build.
- The in-game Menu will show 10 sections, and each section can have multiple levels. Players will have to complete all levels in a section before the menu unlocks that section to jump to.
- Level progress is saved in the NSUserDefaults. So even if the game quits, players will have a variable saved for the number of levels they have completed.
- High scores are also saved in NSUserDefaults
- You can set the number of characters to toss per level and how much score is required to pass the level.
- You can set bonuses per level for the number of characters that haven’t been used to pass the level.
- You can change the layers of background art on a per level basis. The clouds, hills, and ground plane are all separate scrolling pieces of art.
- Drop in your own .mp3 files for sound fx or background music.
- Includes three sound preferences which get saved even if the player quits the game. So players can enable or disable Sound FX, Voice FX, or Ambient FX ( or Background Music )
The Extra Special Cool Features….
This wouldn’t be a “Cartoon” Smart Template if we didn’t add some easy ways to make this game really come alive with your own art and animation.
Here’s some of the artistic highlights…
- It is incredibly easy to add a variety of shapes to your level’s stack with built in vector definitions for the collision environment. For example: squares, triangles, circles, trapezoids, parallelograms, hexagons, octagons, pentagons are preset properties for your stack object. Want to know more? Skip to 00:07:21 for details in the demo video below
- Includes two animated impact FX that can be played anytime a stack object breaks (you can add as many more as you like). Different FX animations can be applied to different objects or enemies.
- Supports custom break animations for stack objects or enemies. So if you want to include even more animation for a specific object breaking apart you can.
- Stacks are incredibly easy to build. We recommend using an art program like Flash or Photoshop to design your stack then just copy the center x and y locations of each object into XCode. Skip to 00:18:53 for details in the demo video below
- Two lines of very easy code add each stack object or enemy to the stack. All your properties for the object are defined in one line. Usually YES or NO values for options like: breaksFromNinja , hasAnimatedBreakFrames, damagesEnemy, breaksOnGround, makeImmovable. Skip to 00:10:44 for details in the demo video below.
- Every Stack Object or Enemy can have a custom point value.
- You can add as many different slingshot characters as you like, depending on level or the order they get thrown in.
- Slingshot characters have different artwork frames for poses like “standing in line to be thrown”, “blinking” , “in air”, “roll”, “roll and impact”, or “on the ground”. You can add as many different poses as you like and choose when they appear.
- Enemies can have damage factors. So it may take more than one collision with a ninja or stack object to damage the enemy enough to be destroyed. In our demo video you’ll notice the enemy gets a bandage or two after being collided.
- Enemies can also have separate animated frames for breaking (for example, the enemy in the template disintegrates )
- Choose between embedded images or a font for the post-object break Scores (which float above the object that broke). Currently the template uses images for scores in values of 100,500,1000, 5000 and 10000.
Converting Cocos2d to Cocos2d-x for Multiplatform support
At Neonchalk, we converted this cocos2d Objective-C code to C++ to be used with cocos2d-x which allows the game to be deployed to all devices that it supports. Today they demonstrated cocos2d-html5 which is amazing. We will contact the author of “Angry Ninjas” to see if the cocos2d-x version can be shared with others or perhaps they will do a tutorial on supporting multiple platforms.
Below is a sequence of images showing the Angry Ninja game from Cartoonsmart running on the Kindle Fire.
Coding a complicated physics game without the right tools is tedious and slow. Fortunately there is a tool that makes this work easy and fast so you can concentrate on creating a great game.
LevelHelper along with SpriteHelper are excellent tools for creating sprite sheets and generating usable physics code. The author of this tool, Vladu Bogdan, is constantly improving the tools allowing you to easily create levels for your games complete with physics working with your sprite sheets taken from SpriteHelper. The tool allows instant testing of the physics using the built in Scene Tester.
The software only works for the MAC and it is well worth purchasing a MAC just for this tool as it will save weeks and months of work for your development project. The author supports cocos2d-x which can be run on several platforms.
The software can be purchased in the Apple App store, more information can be found at http://www.levelhelper.org/
Ray Wenderlich has excellent tutorials for cocos2d and Vladu has contributed an excellent tutorial series using LevelHelper and SpriteHelper.
The final code for this tutorial series has been converted to cocos2d-x and will be posted soon. Using cocos2d-x and Marmalade SDK it was an easy task to get the finished game onto the Kindle Fire.
Cocos2d to Cocos2d-x
The difference between the Objective-C and C++ code can be viewed here and can be used as an aid to converting between the languages for cocos2d to cocos2d-x conversions.
A simple but interesting demo of using Cocos2d with Box2D physics can be found at http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/
The Objective-C code using Cocos2d can be found at that link.
Converting it to Cocos2d-x and C++ was very easy and provides another good example of porting existing Cocos2d code to various platforms using C++.
Most of the code on this blog can also be deployed using the native code from Cocos2d-x or Marmalade SDK for those that are targeting multiple platforms. Just look for the include “mkb” file.
The only part about this post that was tricky was doing the Box2d debug draw but luckily the code is included in the Box2d test code in Cocos2d-x. The extra files required were GLES-Render.cpp and GLES-Render.h and they are included.
The source code can be found at: http://www.neonchalk.com/files/RadialGravity.zip
You will need to have the cocos2d-x development environment. Load the cocos2d-win32.vc2008.sln (for example) and just add the RadialGravity.win32.vcproj to the solution.
The code has been updated and tested with cocos2d-1.01-x-0.11.0 release that includes and updated version of Box2D.
A good way of learning Cocos2d-x is to convert an existing Cocos2d game. One that we chose was the tweeump game. The code for this game is at: https://code.google.com/p/tweejump-cocos2dx/
Some discussion about the development is located on the Cocos2d-x forums at: http://www.cocos2d-x.org/boards/6/topics/1652
The main difficulty in doing this port was the the original tweejump located at https://github.com/dvydra/tweejump was based on an older cocos2d.
The Objective C was that not difficult to port to C++ and the rules of translating Objective C to C++ posted here http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Rules_of_translating_objc_to_cpp provided some guidance.
Keep an eye on the repository for the Tweejump as updates to the code will be made until it is a good solid example of a game using Cocos2D-x with C++.
For a developer, being able to develop one code base for all platforms is the best way to capture the largest market for their application.
Two SDK’s will let the developer accomplish this. The first one is Cocos2d-x, take a look at their website http://www.cocos2d-x.org. This is a multi-platform, light weight and developer friendly C++ 2D mobile game engine, open source and released under MIT License. It is spawned off of the famous “cocos2d-iphone” project and will be kept in sync with it.
The platforms supported are Win32, Android, iPhone, Wophone, QNX, Bada and Marmalade SDK.
What is great about cocos2d is that there are many tutorials and examples. The only downside now is that most of them are in Objective-C for the iPhone.
Some of these tutorials can be found at the following links:
From the original cocos2d iphone project:
Ray Wenderlich has some very detailed tutorials:
There are also many books:
In the next few installments, this blog will post several of these tutorials and examples rewritten in C++ to help others get started with cocos2d-x.