I’m using cocos2d-x 3.7.1
I have a Node in my Scene, I’m adding child Nodes to that Node. (HexField is a subclass of 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);
}
}
If there is only one HexField added
int rhombusSizeX = 1;
int rhombusSizeY = 1;
The touch->getLocation() in HexField::onTouchBegan is reported as expected in World Coordinates.
If there is more than one HexField added
int rhombusSizeX = 5;
int rhombusSizeY = 5;
touch->getLocation() returns coordinates relative to the “one before last” added HexField which in this case will be HexField 3,4.
Why is that so? Is it a bug?