九、cocos2d-x一些实用的代码片段

前端之家收集整理的这篇文章主要介绍了九、cocos2d-x一些实用的代码片段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

双击按钮(cpp)

void HelloWorld::callback1()
{
    _tapCount = 0;
}
void HelloWorld::menuCloseCallback(Ref* pSender)
{
    _tapCount = _tapCount + 1;
    if (_tapCount == 1)
    {
        DelayTime* delayAction = DelayTime::create(0.3);
        CallFunc*resetAction = CallFunc::create(CC_CALLBACK_0(HelloWorld::callback1,this));
        Sequence *seq = Sequence::create(delayAction,resetAction,NULL);
        this->runAction(seq);
    }
    else{
        log("double tap");
    };

}

给Text设置时分秒(Lua)

-- 根據毫秒數,給一個text设置时,分,秒
function setTime(text,time)
    local hour = math.floor(time / 3600)
    local minute = math.floor((time % 3600) / 60)
    local second = time % 3600 % 60
    text:setString(string.format("%02d:%02d:%02d",hour,minute,second))

end 

在滑动容器中,判断按钮点击还是滑动

local isTouch = 0
        local function iconCallBack(widget,type)
            if type == 0 then
                isTouch = 0
            elseif type == 1 then
                isTouch = isTouch+1
            else
                if isTouch<7 then
                end
            end

        end

       button:setSwallowTouches(false)
原文链接:https://www.f2er.com/cocos2dx/340775.html

猜你在找的Cocos2d-x相关文章