Monthly Archive for October, 2010

Verlet rope

Introduction

In this brief article we’ll be taking a look at an efficient way of creating ropes in our cocos2d games that use box2d, starting from a cocos2s+box2d template project.
We will be using box2d’s latest addition, the b2RopeJoint to constrict two bodies with a rope joint (a maximum distance joint, one might also call it), so as always big thanks to Erin Catto for all his hard work on box2d.
We will also be using a small set of classes I wrote, VRope, that use Verlet integration to calculate the points of the rope, using a CCSpriteBatchNode to visually draw the rope in our game.

Click for video

It’s worth mentioning that using Box2D isn’t strictly necessary, you could still use the VRope class to draw a rope between two given points in other scenarios (for example using Chipmunk, your own physics system, or simply updating the two points manually) and have it react under gravity. With that in mind, the class also has some helper methods to use it with CGPoints only. (somethingWithPoints methods)

Setting up the project

First things first, make sure you have the latest version of Cocos2D and create a new project with the “Cocos2d Box2d Application” template. You will then need to update Box2D to the latest committed version, which you can find at http://code.google.com/p/box2d/source/checkout
To update Box2D in your current project:

  • From within XCode, delete the Box2D folder group from the “cocos2d Sources” folder (Delete References)
  • From Finder, go to your project’s folder and delete the Box2D folder
  • Copy over the latest version of Box2D back into your project’s folder (make sure you only copy the most deep rooted “Box2D” folder, and delete CMakeLists.txt and Box2DConfig.cmake)
  • Back to XCode, Project -> Add to Project, select the Box2D folder, make sure create groups (not folder reference) is selected, Add

This should give you a working Cocos2D project, updated with the latest Box2D source that has the b2RopeJoint ready to use.
If you’re not running the latest version of cocos2d (0.99.5-rc0) but still want to use VRope, you’ll need to rename CCSpriteBatchNode back to CCSpriteSheet, the rest should work as is.

Using b2RopeJoint

Using the new b2RopeJoint is very easy, it’s similar to the b2DistanceJoint, but unlike other joints it doesn’t have an Initialize method.

//define rope joint, params: two b2bodies, two local anchor points, length of rope
b2RopeJointDef jd;
jd.bodyA=body1; //define bodies
jd.bodyB=body2;
jd.localAnchorA = b2Vec2(0,0); //define anchors
jd.localAnchorB = b2Vec2(0,0);
jd.maxLength= (body2->GetPosition() - body1->GetPosition()).Length(); //define max length of joint = current distance between bodies
world->CreateJoint(&jd); //create joint

Continue reading ‘Verlet rope’

cocos2d v0.99.5-rc0 released – Improved Retina Display support

cocos2d v0.99.5-rc0 just has been released.

Downloadcocos2d-iphone-0.99.5-rc0.tar.gz

Release NotesRelease Notes v0.99.5-rc0

API Referencev0.99.5-rc0 API Reference

Highlights:

  • Improved Retina Display support
  • Improved templates

and many bug fixes and little improvements.

Full ChangelogCHANGELOG

How to create Retina Display games (updated for v0.99.5-rc0):

Get ready for the Mac App Store

Apple announced today that in 90 days the Mac App Store will be ready!

The Mac App Store will be similar to the App Store, but instead of distributing iOS applications, it will distribute Mac applications.

This is big news for cocos2d users, since cocos2d already supports Mac!!

The guidelines and other requirements for the Mac App Store are online:

So, download the latest cocos2d version, and start porting your cocos2d game for Mac!

More info regarding cocos2d for Mac: cocos2d includes Mac support

Trainyard: Another cocos2d successful story

Trainyard is a very polished, well designed, orignal game.

As of today, the game is:

  • 2nd Top Paid App in US
  • 2nd Top Free App in US
  • 3rd Top Grossing App in US

What is very interesting, is that this game was developed by just 1 person (Matt Rix) with a lot of hard work, hard work, hard work and conviction. I suggest reading the story behind this game. It is very inspiring!

It contains details about the whole lifecycle of a game:

  • Game design
  • Tools
  • Marketing

and more.

Haven’t you tried Trainyard yet?




Social Widgets powered by AB-WebLog.com.