Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I am currently building a cocos2d-x game which incorporates pinch zoom using CCLayerPanZoom class which can be found here

The problem is basically when using CCFollow and zooming and out, it does'nt zoom on the actually followed node, so the camera appears to zoom towards the bottom left corner of the screen, when I would rather it zoom centrally on the followed node.

If I could resolve this I would pretty darn happy. I converted a fix from the cocos2d objective C version in the CCfollow class to cocos2d-x which improved the issue,but if you look at the post in latter link you will see the guy is having the exact same problem, he gave up on fixing it sadly.

I think its close but I don't really know what going on, hopefully someone out there has already faced and fixed this problem.

My converted code is below.

    CCPoint p1 = ccpMult(m_obHalfScreenSize, m_pTarget->getScale() );
    CCPoint p2 = ccpMult(m_pobFollowedNode->getPosition(), m_pTarget->getScale()  );
    CCPoint offect = ccpMult(ccpSub(p1, m_obHalfScreenSize), 0.5f);
    CCPoint tempPos = ccpAdd(ccpSub(p1, p2), offect);

I have attached before and after to hopefully make things more clear.

Before layer zoom centre is fine After layer zoom centre is off

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.