O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

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

Creating an analog stick

By building on the last recipe, we can create a more sophisticated virtual analog stick. This input method measures vector magnitude as well as direction. We've also created a cool looking visual effect for the analog stick.

Creating an analog stick

Getting ready

Please refer to the project RecipeCollection01 for full working code of this recipe.

How to do it...

Execute the following code:

#import "TouchableSprite.h" //AnalogStick.h @interface AnalogStick : TouchableSprite { @public CGPoint _pressedVector; //Internal _pressedVector with no outer dead zone CCSprite *nub; CCSprite *bar; int direction; } @property (readonly) CGPoint pressedVector; //External ...

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