您好,登錄后才能下訂單哦!
1.什么是斷言?
斷言assert 是僅在Debug 版本起作用的宏,它用于檢查“不應(yīng)該”發(fā)生的情況。如果是Release版本,編譯器忽略所有的斷言(看成空語句)。
#define CC_ASSERT(cond) assert(cond)
#if COCOS2D_DEBUG > 0 extern bool CC_DLL cc_assert_script_compatible(const char *msg); #define CCAssert(cond, msg) do { \ if (!(cond)) { \ if (!cc_assert_script_compatible(msg) && strlen(msg)) \ cocos2d::CCLog("Assert failed: %s", msg); \ CC_ASSERT(cond); \ } \ } while (0) #else #define CCAssert(cond, msg) ((void)(cond)) #endif
例子:
//addChild方法,如果要添加的子節(jié)點(diǎn)為空,就停住了,并打印信息“Argument must be non-nil” void CCNode::addChild(CCNode *child) { //不為空不成立,就是為空啦 CCAssert( child != NULL, "Argument must be non-nil"); this->addChild(child, child->m_nZOrder, child->m_nTag); }
2.函數(shù)回調(diào),主要有三種方式(無參數(shù),一個(gè)參數(shù),二個(gè)參數(shù))
void call1(); void call2(CCNode* node); void call3(CCNode* node,void* data);
實(shí)現(xiàn):
void HelloWorld::call1(){ CCLog("call1"); } void HelloWorld::call2(CCNode* node){ CCLog("call2"); } void HelloWorld::call3(CCNode* node,void* data){ CCLog("call3"); CCSprite* sp =(CCSprite*) data; sp->setScale(2.0f); }
函數(shù)回調(diào):
CCSprite* sp = CCSprite::create("CloseNormal.png"); sp->setPosition(CCPointZero); addChild(sp); CCJumpTo* jump = CCJumpTo::create(1, ccp(400,20), 60, 8); // 無參 CCCallFunc* fun1 = CCCallFunc::create(this, callfunc_selector(HelloWorld::call1)); //一個(gè)參數(shù) CCCallFunc* fun2 = CCCallFuncN::create(this, callfuncN_selector(HelloWorld::call2)); //兩個(gè)參數(shù) CCCallFunc* fun3 = CCCallFuncND::create(this, callfuncND_selector(HelloWorld::call3),(void*)sp); CCSequence* seq = CCSequence::create(jump,fun1,fun2,fun3,0); sp->runAction(seq);
3.CCProgressTo使用:
//TestCpp中的例子 CCSprite* sp = CCSprite::create("CloseNormal.png"); sp->setPosition(CCPointZero); addChild(sp); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCProgressTo *to1 = CCProgressTo::create(2, 100); CCProgressTimer *left = CCProgressTimer::create(sp); left->setType( kCCProgressTimerTypeRadial ); //圓形進(jìn)度 addChild(left); left->setPosition(ccp(100, s.height/2)); left->runAction( CCRepeatForever::create(to1));
哈哈,一天一點(diǎn)進(jìn)步,加油
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。