【发布时间】:2015-09-05 14:26:09
【问题描述】:
我使用的是 cocos2d-x 3.7.1
我的场景中有一个节点,我正在向该节点添加子节点。 (HexField 是 Node 的子类)
int rhombusSizeX = 1;
int rhombusSizeY = 2;
for (int y = 0; y < rhombusSizeY; ++y){
for (int x = 0; x < rhombusSizeX; ++x){
HexField* field = HexField::create();
field->setPosition(Vec2(x*30 + y*15, y*30));
field->setName("HexField " + to_string(x) + "," + to_string(y));
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(HexField::onTouchBegan, field);
listener->onTouchMoved = CC_CALLBACK_2(HexField::onTouchMoved, field);
listener->onTouchEnded = CC_CALLBACK_2(HexField::onTouchEnded, field);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, field);
this->addChild(field, 1);
}
}
如果只添加一个HexField
int rhombusSizeX = 1;
int rhombusSizeY = 1;
HexField::onTouchBegan 中的 touch->getLocation() 在世界坐标中按预期报告。
如果添加了多个HexField
int rhombusSizeX = 5;
int rhombusSizeY = 5;
touch->getLocation() 返回相对于“前一个”添加的 HexField 的坐标,在本例中为 HexField 3,4。
为什么会这样?是bug吗?
【问题讨论】:
标签: c++ c++11 cocos2d-x cocos2d-x-3.0