Bug in CCScrollView zooming and setZoomScale()

Bug in CCScrollView zooming and setZoomScale()
0.0 0


Hi there,

I am referring to the most recent version of cocos2d-x (2.1.3).

I think there is a bug in CCScrollView. If you tap the scroll view with 2 fingers CCScrollView::ccTouchMoved() is called and the following code is being executed:

else if (m_pTouches->count() == 2 && !m_bDragging)
const float len = ccpDistance(m_pContainer->convertTouchToNodeSpace((CCTouch*)m_pTouches->objectAtIndex(0)), m_pContainer->convertTouchToNodeSpace((CCTouch*)m_pTouches->objectAtIndex(1)));

So I assume that the view should be zoomed in when performing a pinch, right? Or what is the purpose of this?

However, in CCScrollView::setZoomScale() the following line does the scaling:
m_pContainer->setScale(MAX(m_fMinScale, MIN(m_fMaxScale, s)));

The problem is: m_fMinScale and m_fMaxScale are class members that are not accessible from the outside, and in initWithViewSize() they are set to 1.0f. They never change their value:
m_fMinScale = m_fMaxScale = 1.0f; (line 122)

This is an issue in our game because we scale down our instance of the Scroll View from the outside (let’s say the container’s scale factor is 0.8). If you then tap the view with 2 fingers the scroll view’s container is always scaled up to 1.0. And it can never scale down again.

Is this a bug? I would like to find a solution for this but I am not sure about the desired behavior of the Scroll View (why would you want to zoom into a scroll view anyway?), and the purpose of these class members m_fMinScale and m_fMaxScale if you cannot change their value.

I’d appreciate any response! Thanks in advance!


I could inherit from CCScrollView and add get/set routines for m_fMinScale and m_fMaxScale. This gave me the pinch-zoom functionality that I was looking for.

It would help if the CCScrollView class directly provided get/set functions for m_fMinScale and m_fMaxScale.


class ZoomView : public CCScrollView {
static ZoomView* create(CCSize size, CCNode* container = NULL)
ZoomView* pRet = new ZoomView();
if (pRet && pRet~~>initWithViewSize)
return pRet;
void setMaxScale(float m) {
m_fMaxScale = m;
} *zoomView;