Touch rotate and zoom

Touch rotate and zoom
0.0 0



I’ve been all over the internet and can’t find the simple stuff for the newest version of Cocos2d-x. Can someone please post some code to, 1. touch rotate a sprite, and 2. pinch zoom on a layer. I need for the .h and .cpp files, not the .h and .mm files. Thanks muchly!


Found this, maybe someone can translate to a .cpp file?

NSArray* allTouches = [[event allTouches] allObjects];
CCLayer gameField = ;
if {
v = [[CCDirector sharedDirector] view];
UITouch tOne = ;
tTwo = [allTouches objectAtIndex:1];
CGPoint firstTouch = [tOne locationInView:v];
CGPoint secondTouch = [tTwo locationInView:v];
CGPoint oldFirstTouch = [tOne previousLocationInView:v];
CGPoint oldSecondTouch = [tTwo previousLocationInView:v];
float oldPinchDistance = ccpDistance(oldFirstTouch, oldSecondTouch);
float newPinchDistance = ccpDistance(firstTouch, secondTouch);

float distanceDelta = newPinchDistance - oldPinchDistance;
NSLog(@“%f”, distanceDelta);
CGPoint pinchCenter = ccpMidpoint(firstTouch, secondTouch);
pinchCenter = [gameField convertToNodeSpace:pinchCenter];

gameField.scale = gameField.scale - distanceDelta / 100;
if (gameField.scale < 0) {

gameField.scale = 0;


Have you looked at the test code in samples/Cpp/TestCpp/Classes? Maybe you can get some ideas from there?


Hark my ears…. where might I find this samples area? In Xcode, the apple development site, this site…? I’m looking everywhere


The samples directory is in your cocos2d-x folder on your computer where you installed cocos2d-x. There are xcode projects for each sample and one big one for TestCpp.
You can also find it on github: