O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding revolute joints

Revolute joints are added between two bodies so that one body can spin around the other. In this example, we will add wheels to the basket.

Getting started

Import the wheel PNG files from the resources folder into the project. Create two new global sprites called spriteWheelL and spriteWheelR in the MainScene.h file.

How to do it…

We will first add a new function called addWheels in the MainScene.m file:

-(void) addWheels{ //left wheel wheelSpriteL = [CCSprite spriteWithImageNamed:@"wheel.png"]; float radius = wheelSpriteL.contentSizeInPoints.width * 0.5f; CCPhysicsBody *body1 = [CCPhysicsBody bodyWithCircleOfRadius:radius andCenter:wheelSpriteL.anchorPointInPoints]; body1.friction = 1.2; body1.type = CCPhysicsBodyTypeDynamic; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required