本文整理汇总了C++中Touch::getPreviousLocationInView方法的典型用法代码示例。如果您正苦于以下问题:C++ Touch::getPreviousLocationInView方法的具体用法?C++ Touch::getPreviousLocationInView怎么用?C++ Touch::getPreviousLocationInView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Touch
的用法示例。
在下文中一共展示了Touch::getPreviousLocationInView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleTouchEvent
int LuaEngine::handleTouchEvent(void* data)
{
if (NULL == data)
return 0;
TouchScriptData* touchScriptData = static_cast<TouchScriptData*>(data);
if (NULL == touchScriptData->nativeObject || NULL == touchScriptData->touch)
return 0;
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchScriptData->nativeObject, ScriptHandlerMgr::HandlerType::TOUCHES);
if (0 == handler)
return 0;
switch (touchScriptData->actionType)
{
case EventTouch::EventCode::BEGAN:
_stack->pushString("began");
break;
case EventTouch::EventCode::MOVED:
_stack->pushString("moved");
break;
case EventTouch::EventCode::ENDED:
_stack->pushString("ended");
break;
case EventTouch::EventCode::CANCELLED:
_stack->pushString("cancelled");
break;
default:
return 0;
}
int ret = 0;
Touch* touch = touchScriptData->touch;
if (NULL != touch) {
const cocos2d::Vec2 pt = Director::getInstance()->convertToGL(touch->getLocationInView());
_stack->pushFloat(pt.x);
_stack->pushFloat(pt.y);
const cocos2d::Vec2 prev_pt = Director::getInstance()->convertToGL(touch->getPreviousLocationInView());
_stack->pushFloat(prev_pt.x);
_stack->pushFloat(prev_pt.y);
ret = _stack->executeFunctionByHandler(handler, 5);
}
_stack->clean();
return ret;
}
示例2: executeNodeTouchesEvent
int LuaEngine::executeNodeTouchesEvent(Node* pNode, int eventType, const std::vector<Touch*>& touches, int phase)
{
CCScriptEventListenersForEvent *listeners = getListeners(pNode, phase == NODE_TOUCH_CAPTURING_PHASE ? NODE_TOUCH_CAPTURE_EVENT : NODE_TOUCH_EVENT);
if (!listeners) return 1;
_stack->clean();
LuaValueDict event;
switch (eventType)
{
case CCTOUCHBEGAN:
event["name"] = LuaValue::stringValue("began");
break;
case CCTOUCHMOVED:
event["name"] = LuaValue::stringValue("moved");
break;
case CCTOUCHENDED:
event["name"] = LuaValue::stringValue("ended");
break;
case CCTOUCHCANCELLED:
event["name"] = LuaValue::stringValue("cancelled");
break;
case CCTOUCHADDED:
event["name"] = LuaValue::stringValue("added");
break;
case CCTOUCHREMOVED:
event["name"] = LuaValue::stringValue("removed");
break;
default:
return 0;
}
event["mode"] = LuaValue::intValue((int)Touch::DispatchMode::ALL_AT_ONCE);
switch (phase)
{
case NODE_TOUCH_CAPTURING_PHASE:
event["phase"] = LuaValue::stringValue("capturing");
break;
case NODE_TOUCH_TARGETING_PHASE:
event["phase"] = LuaValue::stringValue("targeting");
break;
default:
event["phase"] = LuaValue::stringValue("unknown");
}
LuaValueDict points;
Director* pDirector = Director::getInstance();
char touchId[16];
for (auto touchIt = touches.begin(); touchIt != touches.end(); ++touchIt)
{
LuaValueDict point;
Touch* pTouch = (Touch*)*touchIt;
sprintf(touchId, "%d", pTouch->getID());
point["id"] = LuaValue::stringValue(touchId);
const Point pt = pDirector->convertToGL(pTouch->getLocationInView());
point["x"] = LuaValue::floatValue(pt.x);
point["y"] = LuaValue::floatValue(pt.y);
const Point prev = pDirector->convertToGL(pTouch->getPreviousLocationInView());
point["prevX"] = LuaValue::floatValue(prev.x);
point["prevY"] = LuaValue::floatValue(prev.y);
points[touchId] = LuaValue::dictValue(point);
}
event["points"] = LuaValue::dictValue(points);
_stack->pushLuaValueDict(event);
bool flagNeedClean = false;
for (auto it=listeners->begin(); it!=listeners->end(); ++it)
{
if ((*it)->removed) {
flagNeedClean = true;
continue;
}
_stack->copyValue(1);
_stack->executeFunctionByHandler((*it)->listener, 1);
_stack->settop(1);
}
cleanListeners(listeners, pNode, flagNeedClean);
_stack->clean();
return 1;
}
示例3: executeScriptTouchHandler
int LuaEventNode::executeScriptTouchHandler(int nEventType, const std::vector<Touch*>& touches, int phase /* = NODE_TOUCH_TARGETING_PHASE */)
{
auto stack = initExecParam(this->getActiveNode(), phase);
if (!stack)
{
return 0;
}
LuaValueDict event;
switch (nEventType)
{
case CCTOUCHBEGAN:
event["name"] = LuaValue::stringValue("began");
break;
case CCTOUCHMOVED:
event["name"] = LuaValue::stringValue("moved");
break;
case CCTOUCHENDED:
event["name"] = LuaValue::stringValue("ended");
break;
case CCTOUCHCANCELLED:
event["name"] = LuaValue::stringValue("cancelled");
break;
case CCTOUCHADDED:
event["name"] = LuaValue::stringValue("added");
break;
case CCTOUCHREMOVED:
event["name"] = LuaValue::stringValue("removed");
break;
default:
return 0;
}
event["mode"] = LuaValue::intValue((int)Touch::DispatchMode::ALL_AT_ONCE);
switch (phase)
{
case NODE_TOUCH_CAPTURING_PHASE:
event["phase"] = LuaValue::stringValue("capturing");
break;
case NODE_TOUCH_TARGETING_PHASE:
event["phase"] = LuaValue::stringValue("targeting");
break;
default:
event["phase"] = LuaValue::stringValue("unknown");
}
LuaValueDict points;
Director* pDirector = Director::getInstance();
char touchId[16];
for (auto touchIt = touches.begin(); touchIt != touches.end(); ++touchIt)
{
LuaValueDict point;
Touch* pTouch = (Touch*)*touchIt;
sprintf(touchId, "%d", pTouch->getID());
point["id"] = LuaValue::stringValue(touchId);
const Point pt = pDirector->convertToGL(pTouch->getLocationInView());
point["x"] = LuaValue::floatValue(pt.x);
point["y"] = LuaValue::floatValue(pt.y);
const Point prev = pDirector->convertToGL(pTouch->getPreviousLocationInView());
point["prevX"] = LuaValue::floatValue(prev.x);
point["prevY"] = LuaValue::floatValue(prev.y);
points[touchId] = LuaValue::dictValue(point);
}
event["points"] = LuaValue::dictValue(points);
return callNodeEventDispatcher(stack, event);
}