Quantcast
Channel: GMT Dev Blog » Box2D
Viewing all articles
Browse latest Browse all 2

How to use Box2D for just Collision Detection with Cocos2D-X

0
0

 

Updated for Cocos2D-X version “cocos2d-2.1rc0-x-2.1.2″.

How to run the sample code:  Download the zip file and move it to the folder “/cocos2d-2.1rc0-x-2.1.2/samples/Cpp/”. Unzip it. Open the project file “HelloCpp-Box2D-CollisionTest-2.1.2/proj.ios/HelloCpp.xcodeproj” (iOS). Android and other users will need to update the build settings in the relevant files.

 

This is a Cocos2D-X collision detection sample that uses Box2D collision vertices to define the shape of the sprite (as opposed to using a rectangle which detects collisions even where the sprite it transparent). Box2D is only being used for collision detection, not gravity or anything else.

You can also see this method in action in my iPhone & iPad game Arrow Mania (click the link and get it free or watch the video).

The code is based on an article by Ray Wenderlich where he implements it with Cocos2D iPhone (Obj C). This version is of course written in C++ for Cocos2D-X. I’m not going to repeat everything from Ray’s article so you should have a read of that, it contains a lot of useful info about the Box2D collision detection and other things. Click here for Ray Wenerlich’s article.

There is also a good guide to using the Vertex Helper app along with important info on rules you need to know when using it: http://www.cocos2d-iphone.org/archives/779

This project also demonstrates the use of the following:

  • Sprite Sheets
  • Supporting SD (low res) and HD (high res). Loads different sprite sheets depending on resolution.
  • Box2D
  • Actions that call functions
  • Playing sounds with SimpleAudioEngine

 

The post How to use Box2D for just Collision Detection with Cocos2D-X appeared first on GMT Dev Blog.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images