您好,登錄后才能下訂單哦!
Action類繼承自CCObject,它有移動(dòng)速度類,跟隨類,以及有限時(shí)間動(dòng)作,其中最后一個(gè)分為瞬時(shí)動(dòng)作,和延時(shí)動(dòng)作。
瞬時(shí)動(dòng)作
CCCallFunc | 回調(diào) |
CCFilpX | X軸轉(zhuǎn) |
CCFilpY | Y軸轉(zhuǎn) |
CCHide | 隱藏 |
CCPlate | 設(shè)置位置 |
CCShow | 顯示 |
延時(shí)動(dòng)作
CCBezierBy/To | 延貝塞兒曲線運(yùn)動(dòng) |
CCBlink | 閃爍 |
CCDelayTime | 延時(shí) |
CCMoveTo/By | 移動(dòng) |
CCRotateTo/By | 旋轉(zhuǎn) |
CCFadeIn | 淡入 |
CCFadeOut | 淡出 |
CCJumpBy/To | 跳躒 |
CCSeuqence | 幀序列,有序執(zhí)行 |
CCTintTo | 色值漸變動(dòng)作 |
CCSpawn | 多個(gè)動(dòng)作同一時(shí)間進(jìn)行 |
CCSaleTo/By | 放大,縮小 |
CCAnimate | 動(dòng)畫 |
CCRereate | 有限次重復(fù) |
CCReverseTime | 時(shí)間逆向動(dòng)作,通過(guò)action->reverse()來(lái)取得實(shí)例對(duì)像 |
CCRepeateForever | 無(wú)限次重復(fù)動(dòng)作 |
CCActionEase | 變速動(dòng)作 |
CCDeccelAmplitude | 有相應(yīng)幅度的動(dòng)作,附動(dòng)作時(shí)間,減速 |
CCAccelAmplitude | 有相應(yīng)幅度的動(dòng)作,附動(dòng)作時(shí)間,加速 |
CCAccelDeccelAmplit | 有相應(yīng)幅度的動(dòng)作,附動(dòng)作時(shí)間,變速 |
貝塞兒曲線的應(yīng)用,參數(shù)1.動(dòng)作時(shí)間,參數(shù)2.貝塞兒曲線的參數(shù)值CCBezierConfig(倆個(gè)控制點(diǎn),一個(gè)終點(diǎn))CCBezierTo/By的區(qū)別,To是絕對(duì)位置,By是相對(duì)位置。
typedef struct _ccBezierConfig { //! end position of the bezier Point endPosition; //! Bezier control point 1 Point controlPoint_1; //! Bezier control point 2 Point controlPoint_2; } ccBezierConfig;
用法例子如下:
Sprite *spr = (Sprite *)this->getChildByTag(33); ccBezierConfig config; config.controlPoint_1 = Point(100,400); config.controlPoint_2 = Point(600,400); config.endPosition = Point(600,100); spr->runAction(CCBezierTo::create(2.0,config));
CCFadeIn動(dòng)作要注意的是首先要把透明度設(shè)為0 ,setOpacity(0);
基本樣條動(dòng)作
有時(shí)會(huì)希望用一些非常規(guī)軌道來(lái)描述的運(yùn)動(dòng)軌跡,只要生成離散的幾個(gè)點(diǎn),對(duì)像就會(huì)根據(jù)這這幾個(gè)點(diǎn)模擬路徑。三個(gè)參數(shù)分別是動(dòng)作時(shí)間,點(diǎn)數(shù)組,拉力系數(shù)。CCCardinalSplineBy/To的區(qū)別,To是絕對(duì)路徑,By是相對(duì)路徑,定義點(diǎn)數(shù)組時(shí),第一個(gè)點(diǎn)設(shè)置為(0,0),否則起始點(diǎn)被忽略。
緩沖動(dòng)作,在實(shí)現(xiàn)運(yùn)動(dòng)的過(guò)程中,經(jīng)常要實(shí)現(xiàn)一些加速或減速的動(dòng)作。Ease系列方法改變了運(yùn)動(dòng)的速度,但并沒(méi)有改變整體時(shí)間。分三類:
In action:action(開始的加速動(dòng)作)
Out action:action(結(jié)束的加速動(dòng)作)
Inout action:action(開始,結(jié)束的加速動(dòng)作)
CCActionEase有很多子類,下面是速度時(shí)間坐標(biāo)圖
指數(shù)緩沖:EaseExponentialIn,EaseExponentialOut,EaseExponentialInOut
塞因緩沖:EaseSineIn,EaseSineOut,EaseSineInOut
跳躍緩沖:EaseBounceIn,EaseBounceOut,EaseBounceInOut
彈性緩沖:EaseElasticIn,EaseElasticOut,EaseElasticInOut
回震緩沖:EaseBackIn, EaseBackOut,EaseBackInOut
組合動(dòng)作:CCSequence,CCSpawn,CCRepeat,CCrepeatForever
可調(diào)整速度動(dòng)作,可以用它對(duì)目標(biāo)動(dòng)作封裝,實(shí)現(xiàn)“慢動(dòng)作”“快進(jìn)”的效果。CCSpeed
延時(shí)動(dòng)作:CCDelayTime,就是一段時(shí)間啥也不干,就一個(gè)參數(shù)時(shí)間,它一般放在一個(gè)CCSquence動(dòng)作序列中引起一些效果。
函數(shù)回調(diào)動(dòng)作CCCallFunc
CCCallFunc
CCCallFunc是執(zhí)行對(duì)應(yīng)的回調(diào)函數(shù),其中回調(diào)函數(shù)不可帶參數(shù).
. CCCallFuncN
CCCallFuncN也是執(zhí)行對(duì)應(yīng)的回調(diào)函數(shù),其中回調(diào)函數(shù)帶一個(gè)參數(shù).
CCCallFuncND
CCCallFuncND也是執(zhí)行對(duì)應(yīng)的回調(diào)函數(shù),其中回調(diào)函數(shù)可帶兩個(gè)參數(shù).
過(guò)程動(dòng)作(載入動(dòng)作),進(jìn)度條,CCProgressTo ,CCProgressFromTo
CCProgressTo第一個(gè)參婁是時(shí)間,第二個(gè)參數(shù)是結(jié)束時(shí)圖片的顯示百分比
CCProgressFromTo第一個(gè)時(shí)間,第二個(gè)是開始時(shí)圖片顯示的百分比,第三個(gè)是結(jié)束時(shí)圖片顯示百分比,CCProgressTimer,傳入精靈對(duì)像來(lái)定義,通過(guò)調(diào)用setType函數(shù)來(lái)設(shè)置動(dòng)畫的類型,kCCProgressTimerTypeRadial是圓形掃描動(dòng)畫,kCCProgressTimerTypeBar是直線的掃描動(dòng)畫。調(diào)用setReverseProgress函數(shù)設(shè)置正反的方向,kCCprogressTimerTypeBar類型通過(guò)setBarChangeRate設(shè)置水平和豎直的變化量。
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } CCProgressTo *progress = CCProgressTo::create(2.0,100); CCProgressTimer *time = CCProgressTimer::create(CCSprite::create("Guide_Light_New.png")); time->setPosition(400,240); this->addChild(time); time->setType(kCCProgressTimerTypeRadial); time->runAction(RepeatForever::create(progress)); return true; }
動(dòng)畫,除了上面的動(dòng)作外,cocos2d-x還有一種動(dòng)作,就是動(dòng)畫CCAnimate,要實(shí)現(xiàn)CCAnimate,還要定義一些CCAnimation
CCAnimationCache是一個(gè)單例,用于緩存所有動(dòng)畫和動(dòng)畫幀,
CCAnimationCache::sharedAnimationCache()->addAnimation(animatin,"run"); CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache(); CCAnimation *animi = animCache->animationByName("run");
通過(guò)CCAnimationCache::sharedAnimationCache()獲得緩存CCAnimationCashe,通過(guò)addAnimation函數(shù)加入緩存動(dòng)畫,并命名,通過(guò)animationByName()取得相應(yīng)的動(dòng)畫。
CCAnimation動(dòng)畫
CCAnimation * animi = Animation::create(); animi->addSpriteFrameWithFile("UI/shengjcg.png"); animi->addSpriteFrameWithFile("UI/shengjicg1.png"); animi->setDelayPerUnit(0.2); CCAnimate *an = Animate::create(animi);
TexturePacker打包工具的簡(jiǎn)單用法
上面的Add Folder打開要打包的一系列圖片,選的時(shí)候注意一下Allow Rotation選項(xiàng)和Trim選項(xiàng)這全根據(jù)情況勾選,默認(rèn)是勾選的,然后調(diào)整大小合適,publicsh導(dǎo)出就可
1.讀取plist文件
CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("baozha.plist"); CCSprite *spr = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("PropsEffect_0_1.png"));
這樣就可以通過(guò)紋理獲得plist文件 中的某個(gè)精靈
2.形成CCAnimation
CCAnimation *HelloWorld::GetAnimate(const char *name,const int count,float delay) { CCArray *a=CCArray::array(); char str[100]; for(int i=0;i<count;++i) { sprintf(str,"%s%d.png",name,i); a->addObject(cache->spriteFrameByName(str)); } CCAnimation *animation = CCAnimation::animationWithSpriteFrames(a,delay); return animation; }
3.做action操作
CCAnimation *animation=GetAnimate("PropsEffect_0_",6,0.2f); spr->runAction(CCRepeat::create(CCAnimate::create(animation),1));
免責(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)容。