cocos2dx中的動做、特效、和動畫

wKioL1UGPMfRh3sPAACgLWCdq4o603.jpg

    Action類繼承自CCObject,它有移動速度類,跟隨類,以及有限時間動做,其中最後一個分爲瞬時動做,和延時動做。
數組

    瞬時動做緩存

CCCallFunc 回調
CCFilpX X軸轉
CCFilpY Y軸轉
CCHide 隱藏
CCPlate 設置位置
CCShow 顯示

    延時動做
ide

CCBezierBy/To 延貝塞兒曲線運動
CCBlink 閃爍
CCDelayTime 延時
CCMoveTo/By 移動
CCRotateTo/By 旋轉
CCFadeIn 淡入
CCFadeOut 淡出
CCJumpBy/To 跳躒
CCSeuqence 幀序列,有序執行
CCTintTo 色值漸變更做
CCSpawn
多個動做同一時間進行
CCSaleTo/By
放大,縮小
CCAnimate
動畫
CCRereate
有限次重複
CCReverseTime
時間逆向動做,經過action->reverse()來取得實例對像
CCRepeateForever
無限次重複動做
CCActionEase
變速動做
CCDeccelAmplitude
有相應幅度的動做,附動做時間,減速
CCAccelAmplitude
有相應幅度的動做,附動做時間,加速
CCAccelDeccelAmplit
有相應幅度的動做,附動做時間,變速

    貝塞兒曲線的應用,參數1.動做時間,參數2.貝塞兒曲線的參數值CCBezierConfig(倆個控制點,一個終點)CCBezierTo/By的區別,To是絕對位置,By是相對位置。函數

 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動做要注意的是首先要把透明度設爲0  ,setOpacity(0);
動畫


    基本樣條動做
ui

    有時會但願用一些很是規軌道來描述的運動軌跡,只要生成離散的幾個點,對像就會根據這這幾個點模擬路徑。三個參數分別是動做時間,點數組,拉力系數。CCCardinalSplineBy/To的區別,To是絕對路徑,By是相對路徑,定義點數組時,第一個點設置爲(0,0),不然起始點被忽略。this

    緩衝動做,在實現運動的過程當中,常常要實現一些加速或減速的動做。Ease系列方法改變了運動的速度,但並無改變總體時間。分三類:
spa

    In action:action(開始的加速動做)
blog

    Out action:action(結束的加速動做)

    Inout action:action(開始,結束的加速動做)

    CCActionEase有不少子類,下面是速度時間座標圖

    指數緩衝:EaseExponentialIn,EaseExponentialOut,EaseExponentialInOut

    

wKiom1UGjO2hdONHAABoz1yoqxA592.jpg

    塞因緩衝:EaseSineIn,EaseSineOut,EaseSineInOut

    

wKiom1UGjWmyLe4yAAB0wJLde8Y514.jpg

    跳躍緩衝:EaseBounceIn,EaseBounceOut,EaseBounceInOut

    

wKiom1UGjd_gR8OAAABy9OrxwBM026.jpg

    彈性緩衝:EaseElasticIn,EaseElasticOut,EaseElasticInOut

   

wKiom1UGjzPgGk_8AAB64rgqpTE301.jpg

    回震緩衝:EaseBackIn, EaseBackOut,EaseBackInOut

    

wKiom1UGj27TmLabAACKc-awzh8803.jpg

    組合動做:CCSequence,CCSpawn,CCRepeat,CCrepeatForever


    可調整速度動做,能夠用它對目標動做封裝,實現「慢動做」「快進」的效果。CCSpeed


    延時動做:CCDelayTime,就是一段時間啥也不幹,就一個參數時間,它通常放在一個CCSquence動做序列中引發一些效果。

        

    函數回調動做CCCallFunc

    CCCallFunc

    CCCallFunc是執行對應的回調函數,其中回調函數不可帶參數.
.   CCCallFuncN
    CCCallFuncN也是執行對應的回調函數,其中回調函數帶一個參數.

    CCCallFuncND

    CCCallFuncND也是執行對應的回調函數,其中回調函數可帶兩個參數.


    過程動做(載入動做),進度條,CCProgressTo ,CCProgressFromTo

    CCProgressTo第一個參婁是時間,第二個參數是結束時圖片的顯示百分比

    CCProgressFromTo第一個時間,第二個是開始時圖片顯示的百分比,第三個是結束時圖片顯示百分比,CCProgressTimer,傳入精靈對像來定義,經過調用setType函數來設置動畫的類型,kCCProgressTimerTypeRadial是圓形掃描動畫,kCCProgressTimerTypeBar是直線的掃描動畫。調用setReverseProgress函數設置正反的方向,kCCprogressTimerTypeBar類型經過setBarChangeRate設置水平和豎直的變化量。  

 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;
    }


    動畫,除了上面的動做外,cocos2d-x還有一種動做,就是動畫CCAnimate,要實現CCAnimate,還要定義一些CCAnimation

    CCAnimationCache是一個單例,用於緩存全部動畫和動畫幀,

 CCAnimationCache::sharedAnimationCache()->addAnimation(animatin,"run");
    CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
    CCAnimation *animi = animCache->animationByName("run");

    經過CCAnimationCache::sharedAnimationCache()得到緩存CCAnimationCashe,經過addAnimation函數加入緩存動畫,並命名,經過animationByName()取得相應的動畫。

    CCAnimation動畫

    CCAnimation * animi = Animation::create();
    animi->addSpriteFrameWithFile("UI/shengjcg.png");
    animi->addSpriteFrameWithFile("UI/shengjicg1.png");
    animi->setDelayPerUnit(0.2);
    CCAnimate *an = Animate::create(animi);


    TexturePacker打包工具的簡單用法

    wKiom1UHmQiC-8foAACTgM8bAsY157.jpg

    上面的Add Folder打開要打包的一系列圖片,選的時候注意一下Allow Rotation選項和Trim選項這全根據狀況勾選,默認是勾選的,而後調整大小合適,publicsh導出就可

    1.讀取plist文件 

    CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache(); 
    cache->addSpriteFramesWithFile("baozha.plist");
    CCSprite *spr = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("PropsEffect_0_1.png"));



    這樣就能夠經過紋理得到plist文件 中的某個精靈

    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));
相關文章
相關標籤/搜索