您的位置:首页 > 移动开发 > Cocos引擎

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

2015-11-18 16:02 507 查看

双击按钮(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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息