意思是我用代码发送一个触摸事件,然后这个游戏接受这个触摸事件
可以
addNodeEventListener(cc.NODE_TOUCH_EVENT, function (event) 添加触摸
setTouchEnabled(true) 设置可触摸
void GLView::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{
if (GLFW_MOUSE_BUTTON_LEFT == button)
{
if (GLFW_PRESS == action)
{
_captured = true;
if (this->getViewPortRect().equals(Rect::ZERO) || this->getViewPortRect().containsPoint(Vec2(_mouseX, _mouseY)))
{
intptr_t id = 0;
this->handleTouchesBegin(1, &id, &_mouseX, &_mouseY);
}
}
else if (GLFW_RELEASE == action)
{
if (_captured)
{
_captured = false;
intptr_t id = 0;
this->handleTouchesEnd(1, &id, &_mouseX, &_mouseY);
}
}
}
//Because OpenGL and cocos2d-x uses different Y axis, we need to convert the coordinate here
float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;
if (GLFW_PRESS == action)
{
EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
event.setCursorPosition(cursorX, cursorY);
event.setMouseButton(button);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
else if (GLFW_RELEASE == action)
{
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
event.setCursorPosition(cursorX, cursorY);
event.setMouseButton(button);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
}
你这个方法是设置可触摸,不是发送触摸事件
请问你这是在哪放置代码的,能用lua实现吗?
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
event.setCursorPosition(cursorX, cursorY);
event.setMouseButton(button);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
翻译成 Lua 吧