在图层中添加2个CCScrollLayer时无法滚动

时间:2014-04-28 07:32:35

标签: c++ cocos2d-x ccscrolllayer

我在这里使用CCScrollLayer文件CCScrollLayer作为我的cocos2d-x项目(版本2.2.2)。

我调整它们使它可以垂直滚动。我遇到了一个问题:当我在一个图层中添加两个CCScrollLayer时,我只能滚动添加的最后一个CCScrollLayer。

这是我的代码:

我将包含两个CCScrollLayer的图层添加到场景

void ChooseMapScene::addSlidingLayers()
{
  mChooseCharacterLayer = createChooseCharaterLayer();
  mChooseCharacterLayer->setPosition(CCPointZero);
  mChooseCharacterLayer->setTouchEnabled(true);      
  this->addChild(mChooseCharacterLayer, GR_FOREGROUND);
}

我在一个图层中添加了SlideCharacter1和SlideCharacter2(chooseCharacterLayer),但只是SlideCharacter2可以滚动

CCLayer* ChooseMapScene::createChooseCharaterLayer()
{
  CCLayer* chooseCharacterLayer = CCLayer::create();
  CCArray* characterArr1 = createCharactersArray(CHARACTER_LEFT_LAYER_POS);
  CCArray* characterArr2 = createCharactersArray(CHARACTER_RIGHT_LAYER_POS);

  mSlideCharacter1 = CCScrollLayerVertical::nodeWithLayers(characterArr1, 0);
  chooseCharacterLayer->addChild(mSlideCharacter1, GR_FOREGROUND);

  mSlideCharacter2 = CCScrollLayerVertical::nodeWithLayers(characterArr2, 0);
  chooseCharacterLayer->addChild(mSlideCharacter2, GR_FOREGROUND);

  // I add SlideCharacter1 and SlideCharacter2 in a layer (chooseCharacterLayer) but just the SlideCharacter2 can scroll

  return chooseCharacterLayer;
}

CCArray* ChooseMapScene::createCharactersArray(CCPoint pPos)
{
  CCArray* characterArr = CCArray::createWithCapacity(NUMBER_CHARACTERS);
  for (int i = 1; i <= NUMBER_CHARACTERS; ++i)
  {
    CCLayer* characterLayer = CCLayer::create();

    CCSprite* character = CCSprite::create(CCString::createWithFormat("Images/Game/Object/c%i.png", i)->getCString());
    character->setPosition(pPos);
    characterLayer->addChild(character, GR_FOREGROUND, i);
    characterArr->addObject(characterLayer);
  }
  return characterArr;
}

1 个答案:

答案 0 :(得分:0)

您可以从SlideCharacter1的触控方式手动调用SlideCharacter2的触控方式(开始,取消,移动,结束)来模拟触控