我在CCLayerPanZoom遇到了几个星期的麻烦,最后还是接近但仍然有问题。我有一个非常大的8000像素x 8000像素的瓷砖地图,我想要的是能够放大到大约2.0f并缩小到大约0.4f。下面的代码非常有用,因为它让我可以平移我的整个图块地图而不是平移边缘 - 这是CCLayerPanZoom的一个常见问题,但代码不允许放大或缩小。我现在已经注释掉了minScale和maxScale,因为它们都没有工作。我试过改变minScale和maxScale的位置,它在任何地方都不起作用。有没有人有任何想法如何使minScale和maxScale工作,所以缩放将起作用?
//PanZoomLayer
_panZoomLayer = [[CCLayerPanZoom node] retain];
[self addChild: _panZoomLayer];
_panZoomLayer.delegate = self;
[_panZoomLayer addChild: _tileMap z :1 tag: kBackgroundTag];
_panZoomLayer.mode = kCCLayerPanZoomModeSheet;
_panZoomLayer.rubberEffectRatio = 0.0f;
CCNode *backgroundZ = [_panZoomLayer getChildByTag: kBackgroundTag];
CGRect boundingRect = CGRectMake(0, 0, 0, 0);
boundingRect.size = [backgroundZ boundingBox].size;
[_panZoomLayer setContentSize: boundingRect.size];
_panZoomLayer.anchorPoint = ccp(0.5f, 0.5f);
_panZoomLayer.position = ccp(0.5f * winSize.width, 0.5f * winSize.height);
_panZoomLayer.panBoundsRect = CGRectMake(0, 0, winSize.width, winSize.height);
_panZoomLayer.minScale = 0.4f;
_panZoomLayer.maxScale = 2.0f;
//end PanZoomLayer
答案 0 :(得分:2)
最后想通了,通过在CCPanZoomLayer上方的代码中添加以下行,最终效果很好。希望这段代码能够帮助那些与cocos2d扩展相抗衡的人
[[[CCDirector sharedDirector] view] setMultipleTouchEnabled:YES];