日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Cocoa學(xué)習(xí)筆記Cocos2d各種動(dòng)作介紹(下)

Cocoa學(xué)習(xí)筆記 Cocos2d 各種動(dòng)作介紹 (上)是本節(jié)介紹的內(nèi)容,繼續(xù)Cocoa學(xué)習(xí)筆記 Cocos2d 各種動(dòng)作介紹 (上)的內(nèi)容開始介紹。我們先來看內(nèi)容。

重復(fù)有限次數(shù) – Repeate

重復(fù)有限的次數(shù)的動(dòng)作示例代碼如下:

 
 
 
  1.  (void) OnRepeat:(id) sender {    
  2.  CGSize s =[[CCDirector sharedDirector] winSize];     
  3.  CGPoint p = ccp(s.width/2, 50);    
  4.  sprite.rotation = 0;     
  5.  [sprite setPosition:p];    
  6.  // 創(chuàng)建動(dòng)作序列    
  7.  id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(s.width - 50, s.height - 50)];    
  8. id ac2 = [CCJumpBy actionWithDuration:2 position:ccp(-400, -200) height:30 jumps:5];    
  9. id ac3 = [CCJumpBy actionWithDuration:2 position:ccp(s.width/2, 0) height:20 jumps:3];    
  10.  id seq = [CCSequence actions:ac1, ac2, ac3, nil];    
  11.  //重復(fù)運(yùn)行上述勱作序列 3 次。    
  12.  [sprite runAction:[CCRepeat actionWithAction:seq times:3]];    
  13. }  

反動(dòng)作 – Reverse

反動(dòng)作就是反向(逆向)執(zhí)行某個(gè)動(dòng)作,支持針對(duì)動(dòng)作序列的反動(dòng)作序列。反動(dòng)作不是一個(gè)專門的類,而是 CCFiniteAction 引入的一個(gè)接口。不是所有的類都支持反動(dòng)作,XxxxTo 類通常不支持反動(dòng)作,XxxxBy 類通常支持。示例如下:

 
 
 
  1. (void) OnReverse:(id) sender {    
  2.  CGSize s =[[CCDirector sharedDirector] winSize];     
  3.  CGPoint p = ccp(s.width/2, 50);    
  4.  sprite.rotation = 0;     
  5.  [sprite setPosition:p];    
  6.  id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(190, 220)];    
  7. // 創(chuàng)建某個(gè)勱作癿反勱作。    
  8.  id ac2 = [ac1 reverse];    
  9.  [sprite runAction:[CCRepeat actionWithAction:[CCSequence actions:ac1, ac2,nil] times:2]];    
  10. }   
  11.  
  12. 動(dòng)畫 – Animation  
  13.  
  14. 動(dòng)畫就是讓精靈自身的連續(xù)執(zhí)行一段影像,形成模擬運(yùn)動(dòng)的效果:行走時(shí)動(dòng)精靈狀態(tài)、打斗時(shí)的狀態(tài)等。  
  15.  
  16.  (void) OnAnimation:(id) sender {    
  17.  
  18. CCAnimation *animation = [AtlasAnimation animationWithName:@"flight" delay:0.2f];    
  19.  // 每幀的內(nèi)容定義。     
  20. for(int i=0;i<3;i++) {    
  21.  int x= i % 3;     
  22.  [animation addFrameWithRect: CGRectMake(x*32, 0, 31,30) ];     
  23.  }    
  24. // 執(zhí)行勱畫效果     
  25.  id action = [CCAnimate actionWithAnimation: animation];     
  26. [sprite runAction:[CCRepeat actionWithAction:action times:10]];    
  27.  }   
  28.  
  29. 無限重復(fù) – RepeatForever   
  30.  
  31. RepeatForever 是從 Action 類直接派生的,因此無法參于序列和同步;自身也無法反向執(zhí)行。該類的作用就是無限期執(zhí)行某個(gè)動(dòng)作或動(dòng)作序列,直到被停止。  
  32.  
  33.  (void) OnRepeatForever:(id) sender {    
  34.  CGSize s =[[Director sharedDirector] winSize];     
  35.  CGPoint p = ccp(100, 50);    
  36. // 飛行噴火模擬勱畫    
  37.  CCAnimation *animation = [CCAnimation animationWithName:@"flight" delay:0.1f];    
  38.  for(int i=0;i<3;i++)     
  39.  {    
  40.  int x= i % 3;    
  41.  [animation addFrameWithRect: CGRectMake(x*32, 0, 31,30) ];     
  42.  }    
  43.  id action = [CCAnimate actionWithAnimation: animation];    
  44.  // 將該動(dòng)畫作為精靈的本征動(dòng)畫,一直運(yùn)行。    
  45.  [sprite runAction:[RepeatForever actionWithAction:action]];    
  46. // 在創(chuàng)建第二個(gè)連續(xù)無限期動(dòng)作序列。疊加二者形成完整效果。     
  47. ccBezierConfig bezier;    
  48.  sprite.rotation = 0;     
  49.  [sprite setPosition:p];    
  50.  bezier.startPosition = ccp(0,0);     
  51.  bezier.controlPoint_1 = ccp(0, s.height/2);     
  52.  bezier.controlPoint_2 = ccp(300, -s.height/2);     
  53.  bezier.endPosition = ccp(300,100);    
  54.  id ac10 = [CCBezierBy actionWithDuration:3 bezier:bezier];    
  55.  id ac11 = [CCTintBy actionWithDuration:0.5 red:0 green:255 blue:255];    
  56.  id ac1 = [CCSpawn actions:ac10, [Repeat actionWithAction:ac11 times:4], nil];    
  57.  id ac2 = [CCSpawn actions:[ac10 reverse], [CCRepeat actionWithAction:ac11 times:4], nil];    
  58.  // 第二個(gè)無限期連續(xù)運(yùn)勱。    
  59.  [sprite runAction:[CCRepeatForever actionWithAction:[CCSequence actions:ac1, ac2,nil]]];    
  60.  }  

速度變化

基本動(dòng)作和組合動(dòng)作實(shí)現(xiàn)了針對(duì)精靈的各種運(yùn)動(dòng)、動(dòng)畫效果的改變,但這樣的改變的速度是不變的,通過 CCEaseAction 為基類的類系和 CCSpeed 類我們可以很方便的修改精靈執(zhí)行動(dòng)作的速度:由快至慢還是由慢至快

EaseIn 由慢至快。

EaseOut 由快至慢

EaseInOut 由慢至快再由快至慢。

EaseSineIn 由慢至快

EaseSineOut 由快至慢

EaseSineInOut 由慢至快再由快至慢。

EaseExponentialIn 由慢至極快。

EaseExponentialOut 由極快至慢。

EaseExponentialInOut 由慢至極快再由極快至慢。

Speed 人工設(shè)定速度,還可通過 SetSpeed 不斷調(diào)整。

擴(kuò)展動(dòng)作

我們已經(jīng)掌握了執(zhí)行各種各樣的動(dòng)作,也可以按照不同的快慢修改動(dòng)作執(zhí)行的時(shí)間, Cocos2D-iPhone 還提供了針對(duì)現(xiàn)有動(dòng)作的擴(kuò)展,以實(shí)現(xiàn)各種靈活的效果。

延時(shí)動(dòng)作 – Delay在動(dòng)作序列中增加一個(gè)時(shí)間間歇:

 
 
 
  1. (void) OnDelay:(id) sender {    
  2.  id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(200, 200)];    
  3.  id ac2 = [ac1 reverse];    
  4. // 實(shí)現(xiàn)一個(gè)等待間歇    
  5. [spriterunAction:[Sequenceactions:ac1,[DelayTime actionWithDuration:1], ac2, nil]];     
  6. }  

函數(shù)調(diào)用 ?

函數(shù)在動(dòng)作序列中間或者結(jié)束調(diào)用某個(gè)函數(shù),執(zhí)行任何需要執(zhí)行的任務(wù):動(dòng)作、狀態(tài)修改等。代碼如下:

 
 
 
  1. (void) OnCallFunc:(id) sender {    
  2. id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(200, 200)];    
  3. id ac2 = [ac1 reverse];    
  4. id acf = [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)];    
  5. [sprite runAction:[CCSequence actions:ac1, acf, ac2, nil]];    
  6. }  

對(duì)應(yīng)的函數(shù)為:(再做一個(gè)動(dòng)作,這就實(shí)現(xiàn)了動(dòng)作、動(dòng)作序列的任意擴(kuò)展和連接)

 
 
 
  1. (void) CallBack1 {    
  2.  [sprite runAction:[CCTintBy actionWithDuration:0.5 red:255 green:0 blue:255]];     
  3.  }  

帶對(duì)象參數(shù) 調(diào)用自定義函數(shù)時(shí),傳遞當(dāng)前對(duì)象。

 
 
 
  1. (void) OnCallFuncN:(id) sender {    
  2.  id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(200, 200)];    
  3.  id ac2 = [ac1 reverse];    
  4. id acf = [CallFuncN actionWithTarget:self selector:@selector(CallBack2:)];    
  5.  [sprite runAction:[CCSequence actions:ac1, acf, ac2, nil]];    
  6.  }  

對(duì)應(yīng)的自定義函數(shù):(這里,我們直接使用了該對(duì)象)

 
 
 
  1. (void) CallBack2:(id)sender {    
  2.  [sender runAction:[CCTintBy actionWithDuration:1 red:255 green:0 blue:255]];     
  3. }  

帶對(duì)象、數(shù)據(jù)參數(shù)調(diào)用自定義函數(shù)時(shí),傳遞當(dāng)前對(duì)象和一個(gè)常量(也可以是指針)。

 
 
 
  1. (void) OnCallFuncND:(id) sender {    
  2.  id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(200, 200)];    
  3.  id ac2 = [ac1 reverse];    
  4.  id acf = [CCCallFuncND actionWithTarget:self selector:@selector(CallBack3:data:) data:(void*)2];    
  5.  [sprite runAction:[CCSequence actions:ac1, acf, ac2, nil]];    
  6.  }  

對(duì)應(yīng)的自定義函數(shù),我們使用了傳遞的對(duì)象和數(shù)據(jù):

 
 
 
  1. (void) CallBack3:(id)sender data:(void*)data {    
  2. [sender runAction:[CCTintBy actionWithDuration:(NSInteger)data red:255 green:0 blue:255]]; }  

小結(jié):Cocoa學(xué)習(xí)筆記 Cocos2d 各種動(dòng)作介紹 (下)的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!


分享標(biāo)題:Cocoa學(xué)習(xí)筆記Cocos2d各種動(dòng)作介紹(下)
當(dāng)前地址:http://www.dlmjj.cn/article/cccecod.html