C++ Cocos2d-x触摸事件坐标系
我正在使用cocos2d-x3.7.1 我的场景中有一个节点,我正在向该节点添加子节点。HexField是Node的一个子类C++ Cocos2d-x触摸事件坐标系,c++,c++11,cocos2d-x,cocos2d-x-3.0,C++,C++11,Cocos2d X,Cocos2d X 3.0,我正在使用cocos2d-x3.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();
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::OnTouch中的touch->getLocation按预期在世界坐标中报告
如果添加了多个HexField
int rhombusSizeX = 1;
int rhombusSizeY = 1;
int rhombusSizeX = 5;
int rhombusSizeY = 5;
touch->getLocation返回相对于上次添加的HexField之前的坐标,在本例中为HexField 3,4
为什么会这样?是虫子吗?我现在找到了答案 这一切都是因为我没有打电话:
Director::getInstance()->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
之后:
Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Director::getInstance()->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
在我的绘图功能中
看起来这个错误升级到了我程序的其他部分,导致了一些奇怪的行为