Cocos2d-x CCFollow Zooming issue

Posted by blakey87 on Game Development See other posts from Game Development or by blakey87
Published on 2013-11-02T18:08:55Z Indexed on 2013/11/02 22:19 UTC
Read the original article Hit count: 654

Filed under:
|
|
|
|

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);
    m_pTarget->setPosition(ccp(clampf(tempPos.x,m_fLeftBoundary,m_fRightBoundary), 
                               clampf(tempPos.y,m_fBottomBoundary,m_fTopBoundary)));

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

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

© Game Development or respective owner

Related posts about c++

Related posts about cocos2d-iphone