Help - after scaling touches no longer hit what they should

Help - after scaling touches no longer hit what they should
0.0 0


Hello all,

I’m making a game that will need adjustable zoom. My problem is when I added some scaling of the main layer (most of my program is an extension of this layer, as suggested in tutorials), I can’t click on the objects I wanted.

My objects positions are defined by the sprites associated with them. ie to return their position they refer to sprite~~>getX.
The touches are converted to world coordinates by the following code:
cocos2d::CCPoint HelloWorld::getWorldCoordFromTouch(cocos2d::CCSet* pTouches){
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);

CCPoint location = touch->getLocationInView();
CCPoint convertedLocation = CCDirector::sharedDirector()->convertToGL(location);

return CCPoint(convertedLocation.x,convertedLocation.y);

To scale, I added this~~>setScale(0.25); from inside my main layer. This has scaled the world so it is 1/4 the size and in the centre of the screen.

My problem is the touches are happening as if the scaling never happened. I have to click where the object was before scaling - then it works as intended.

Is there a way to take the scaling factor into account when working out where I clicked? Is this something that convertToGL should already be doing?


I wonder if you should pass your touch location through this->convertTouchToNodeSpace(touch);

I know this works for scrolling a layer, but maybe it works for scaling a layer.