Archive for the ‘cocos2dx’ Category

Using LevelHelper without Box2d for Cocos2d-X

Thursday, November 8th, 2012

I have been trying out LevelHelper recently and it has been very useful when making games that have a fair bit of physics.

I was looking at making a really simple game that did not require physics. Thats where LevelHelper seemed to fall over. Since the editor generates code for you and that code has reference to Box2D.

Fear not for all is not lost, you can still use LevelHelper without implementing the physics. You still need use the Cocos2D-X with Box2D template in xCode. You just don’t attach the physics properties.

So follow the tutorials on the LevelHelper site. When you get to the bellow line of code in the second video:

The first parameter “world” is used to attach the physics properties. The second parameter “this” is what all the image assets in LevelHelper level are attached to. All you need to do is change the above line to:

Now just ignore any code to do with physics and Box2D.

Implementing CCCallFunc Cocos2d-X 2.0

Thursday, August 2nd, 2012

This is a simple way of implementing CCCallFunc.

ClassA wants to pass a function reference to ClassB.

CCCallFunc calls a function without any parameters. If you want to get the CCObject that called it then use CCCallFuncN and if you want to pass your own data use CCCallFuncND

In ClassB header create a variable to hold the callFunction.

In ClassB implementation call the passed in function.

In class ClassA implementation.

Creating Frame Animation in Cocos2d-X 2.0 Using a Sprite Sheet

Saturday, July 28th, 2012

Since the Cocos2d-X 2.0 rc2 a lot of the initialisation has changed so this code works in Cocos2d-X 2.0.

First create a sprite sheet so we can load it in.

Once you have created the Sprite Sheet you will end up with a image file and plist.


I like to name my sprites like this:



It makes creating the animations easier. My code below is depended on the above naming convention.

Create Cocos2d-X 2.0 Sprite Sheet

Sunday, July 22nd, 2012

Cocos2dx is the C++ implementation of Cocos2d. Even though it is C++ and cross platform it still uses plists. There are probably a lot of tools out there that can help you create these sprite sheets. I am currently using SpriteHelper which has export settings specifically targeting Cocos2D-X. I used to use Texture Packer for Cocos2D because it has a nice PVR viewer.

The main reason i am using SpriteHelper is because of Level Helper. Level Helper looks like it has a lot of potential.