0

我正在努力将我的 CCScrollLayer.cpp 代码转换为更多的 CCPicker 代码。在 CCScrollLayer 中,我定义了一个基础层 (CCColorLayer) 来保存所有菜单对象。我还有一个包含 ScrollLayer(使用 glScissor)的边框,称为“overlay”,我希望它是完全静态的。

在目标 C 中:

...
    self.baseLayer = [CCLayerColor layerWithColor:(ccColor4B){150,150,150,0} width:s.width height:imgSize.height * numPages];

    for (int i=0; i < [arrayPages count]; i++) {
        CCNode* n = arrayPages[i];
        n.position = ccp(s.width/2, s.height/2 + i * (imgSize.height + padding)); 
        [baselayer addChild:n];
    }

    baseLayer.position = ccp(-s.width/2, -s.height/2 - s.height * currentPage);
    [self addChild:baselayer];
...

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event 
{

        CGPoint n = [self convertTouchToNodeSpace:touch];
        baselayer.position = ccp(touchStartedbaseLayerPosition.x, touchStartedbaseLayerPosition.y + n.y - touchStartedPoint.y);

}

在 C++ 中

...
        overlay=new CCSprite();
        overlay->initWithFile("overlay.png");
        overlay->setPosition(ccp(300,300));
        overlay->autorelease();

        CCLayerColor* baselayer = new CCLayerColor();
        baselayer->initWithColor(ccc4(255, 255, 255,255));
        baselayer->setOpacity(255);
        baselayer->setContentSize(CCSizeMake(s.width/10, (layers->count()*scrollWidth)));
        baselayer->setPosition(s.width*.41,300);
        baselayer->autorelease();

        // Loop through the array and add the screens
        unsigned int i;
        for (i=0; i<layers->count(); i++)
        {
            CCLayer* l = static_cast<CCLayer*>(layers->objectAtIndex(i));
            l->setAnchorPoint(ccp(0,0));
            l->setPosition(ccp(s.width/40,(i*scrollWidth)));
             baselayer->addChild(l);
        }

        this->addChild(baselayer,1);
        this->addChild(overlay,1);
...

void CCScrollLayer::ccTouchMoved(CCTouch *touch, CCEvent *withEvent)
{

    CCPoint touchPoint = touch->getLocation(); // Get the touch position
    touchPoint = this->getParent()->convertToNodeSpace(touchPoint);

    baselayer->setPosition(ccp(0,(-(currentScreen-1)*scrollWidth)+(touchPoint.y-startSwipe)));
}

我不确定我做错了什么,但是当我尝试开始滚动时,我在 touchdispatcher 中遇到了一个致命错误

                case CCTOUCHMOVED:
                    pHandler->getDelegate()->ccTouchMoved(pTouch, pEvent);

我猜我在这里遗漏了一些简单的东西。你能指出我的写作方向吗?

4

0 回答 0