int CCLuaEngine::executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch)
{
    CCTouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry();
    int nHandler = pScriptHandlerEntry->getHandler();
    if (!nHandler) return 0;
    
    switch (eventType)
    {
        case CCTOUCHBEGAN:
            m_stack->pushString("began");
            break;
            
        case CCTOUCHMOVED:
            m_stack->pushString("moved");
            break;
            
        case CCTOUCHENDED:
            m_stack->pushString("ended");
            break;
            
        case CCTOUCHCANCELLED:
            m_stack->pushString("cancelled");
            break;
            
        default:
            return 0;
    }
    
    const CCPoint pt = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
    m_stack->pushFloat(pt.x);
    m_stack->pushFloat(pt.y);
    return m_stack->executeFunctionByHandler(nHandler, 3);
}
Exemple #2
0
int CCLuaEngine::executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches)
{
    int ret = 0;
    do 
    {
        CCTouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry();
        CC_BREAK_IF(NULL == pScriptHandlerEntry);
        int nScriptHandler = pScriptHandlerEntry->getHandler();
        CC_BREAK_IF(0 == nScriptHandler);
        
        cleanStack();
        lua_pushinteger(m_state, eventType);
        lua_newtable(m_state);

        CCDirector* pDirector = CCDirector::sharedDirector();
        CCSetIterator it = pTouches->begin();
        CCTouch* pTouch;
        int n = 1;
        while (it != pTouches->end())
        {
            pTouch = (CCTouch*)*it;
            CCPoint pt = pDirector->convertToGL(pTouch->getLocationInView());
            lua_pushnumber(m_state, pt.x);
            lua_rawseti(m_state, -2, n++);
            lua_pushnumber(m_state, pt.y);
            lua_rawseti(m_state, -2, n++);
            ++it;
        }

        ret = executeFunctionByHandler(nScriptHandler, 2);
    } while (0);

    return ret;
}
Exemple #3
0
int CCLuaEngine::executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches)
{
    CCTouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry();
    if (!pScriptHandlerEntry) return 0;
    int nHandler = pScriptHandlerEntry->getHandler();
    if (!nHandler) return 0;
    
    switch (eventType)
    {
        case CCTOUCHBEGAN:
            m_stack->pushString("began");
            break;
            
        case CCTOUCHMOVED:
            m_stack->pushString("moved");
            break;
            
        case CCTOUCHENDED:
            m_stack->pushString("ended");
            break;
            
        case CCTOUCHCANCELLED:
            m_stack->pushString("cancelled");
            break;
            
        default:
            return 0;
    }

    CCDirector* pDirector = CCDirector::sharedDirector();
    lua_State *L = m_stack->getLuaState();
    lua_newtable(L);
    int i = 1;
    for (CCSetIterator it = pTouches->begin(); it != pTouches->end(); ++it)
    {
        CCTouch* pTouch = (CCTouch*)*it;
        CCPoint 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 = m_stack->executeFunctionByHandler(nHandler, 2);
    m_stack->clean();
    return ret;
}
Exemple #4
0
// functions for excute touch event
int CCLuaEngine::executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch)
{
    int ret = 0;
    do 
    {
        CCTouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry();
        CC_BREAK_IF(NULL == pScriptHandlerEntry);
        int nScriptHandler = pScriptHandlerEntry->getHandler();
        CC_BREAK_IF(0 == nScriptHandler);
        
        cleanStack();
        CCPoint pt = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
        lua_pushinteger(m_state, eventType);
        lua_pushnumber(m_state, pt.x);
        lua_pushnumber(m_state, pt.y);
        ret = executeFunctionByHandler(nScriptHandler, 3);
    } while (0);
    return ret;
}