TouchScriptHandlerEntry* TouchScriptHandlerEntry::create(int handler, bool isMultiTouches, int priority, bool swallowsTouches) { TouchScriptHandlerEntry* entry = new (std::nothrow) TouchScriptHandlerEntry(handler); entry->init(isMultiTouches, priority, swallowsTouches); entry->autorelease(); return entry; }
TouchScriptHandlerEntry* TouchScriptHandlerEntry::create(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) { TouchScriptHandlerEntry* pEntry = new TouchScriptHandlerEntry(nHandler); pEntry->init(bIsMultiTouches, nPriority, bSwallowsTouches); pEntry->autorelease(); return pEntry; }
int LuaEngine::executeLayerTouchesEvent(Layer* pLayer, int eventType, Set *pTouches) { TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry(); if (!pScriptHandlerEntry) return 0; int nHandler = pScriptHandlerEntry->getHandler(); if (!nHandler) return 0; switch (eventType) { case CCTOUCHBEGAN: _stack->pushString("began"); break; case CCTOUCHMOVED: _stack->pushString("moved"); break; case CCTOUCHENDED: _stack->pushString("ended"); break; case CCTOUCHCANCELLED: _stack->pushString("cancelled"); break; default: return 0; } Director* pDirector = Director::sharedDirector(); lua_State *L = _stack->getLuaState(); lua_newtable(L); int i = 1; for (SetIterator it = pTouches->begin(); it != pTouches->end(); ++it) { Touch* pTouch = (Touch*)*it; Point pt = pDirector->convertToGL(pTouch->getLocationInView()); lua_pushnumber(L, pt.x); lua_rawseti(L, -2, i++); lua_pushnumber(L, pt.y); lua_rawseti(L, -2, i++); lua_pushinteger(L, pTouch->getID()); lua_rawseti(L, -2, i++); } int ret = _stack->executeFunctionByHandler(nHandler, 2); _stack->clean(); return ret; }
int LuaEngine::executeLayerTouchEvent(Layer* pLayer, int eventType, Touch *pTouch) { TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry(); if (!pScriptHandlerEntry) return 0; int nHandler = pScriptHandlerEntry->getHandler(); if (!nHandler) return 0; switch (eventType) { case CCTOUCHBEGAN: _stack->pushString("began"); break; case CCTOUCHMOVED: _stack->pushString("moved"); break; case CCTOUCHENDED: _stack->pushString("ended"); break; case CCTOUCHCANCELLED: _stack->pushString("cancelled"); break; default: return 0; } const Point pt = Director::sharedDirector()->convertToGL(pTouch->getLocationInView()); _stack->pushFloat(pt.x); _stack->pushFloat(pt.y); int ret = _stack->executeFunctionByHandler(nHandler, 3); _stack->clean(); return ret; }