我有一个 ui::ScrollView 包含许多精灵。
我创建了每个精灵并通过执行以下操作为每个精灵添加了一个触摸侦听器:
for(int i=0; i < 5; i++){
Sprite* foo = Sprite::createWithSpriteFrameName("foo");
myScrollView->addChild(foo);
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [this,somestring](Touch* touch, Event* event){
......some code
};
listener->onTouchMoved = [foo,this,somestring](Touch* touch, Event* event){
......some code
};
listener->onTouchEnded = [foo,this,somestring](Touch* touch, Event* event){
......some code
};
foo->getEventDispatcher->addEventListenerWithSceneGraphPriority(listener1,foo);
}
问题是,如果我在屏幕上单击 ANYWHERE,它似乎会触发循环中创建的所有精灵的触摸事件。我创建侦听器的方式有什么不正确的,还是与 ui::ScrollView 中的触摸冲突有关?
我正在使用 v 3.10