偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iPhone游戲開(kāi)發(fā)之Cocos2d中Actions介紹

移動(dòng)開(kāi)發(fā) iOS 游戲開(kāi)發(fā)
本文主要是來(lái)介紹iphone游戲開(kāi)發(fā)中Cocos2d的Actions介紹,來(lái)學(xué)習(xí)Actions的使用方法,來(lái)看詳細(xì)內(nèi)容。

iPhone游戲開(kāi)發(fā)中Cocos2dActions介紹是本文要介紹的內(nèi)容,Action就好像給一個(gè)cocosNode對(duì)象的命令。這些動(dòng)作通常用來(lái)改變物體的屬性,例如位置,旋轉(zhuǎn),縮放等。如果這些屬性在一段時(shí)間只能被修改的話,那么這中叫做 IntervalAction 的Action。否則,它們叫做InstantAction 的動(dòng)作。

例如:MoveBy 動(dòng)作,在一段時(shí)間之內(nèi),改變了位置這個(gè)屬性 ,也就是說(shuō)它是一個(gè)IntervalAction的Action。

  1. # Move a sprite 50 pixels to the right, and 10 pixels to the top over 2 seconds.  
  2. sprite runAction: [MoveBy actionWithDuration:2 position:ccp(50,10)]];  

IntervalAction 有一些很有趣的屬性

它們可以通過(guò)時(shí)間改變來(lái)進(jìn)行加速

  1. EaseIn   
  2. EaseOut   
  3. EaseInOut   
  4. Speed   
  5. Etc. (See the EaseActionsTest.m example for more info)  

所有相對(duì)的動(dòng)作(以By結(jié)尾的)和一些絕對(duì)的動(dòng)作(以 To結(jié)尾的)都有一個(gè)翻轉(zhuǎn)的動(dòng)作,執(zhí)行了一個(gè)相反方向的操作。 你可以使用pause/resume 來(lái)停止和恢復(fù)action

  1.  # Pause actions  
  2. [[ActionManager sharedManager ] pauseAllActionsForTarget:sprite ] ;  
  3.  
  4. # resume actions  
  5. [[ActionManager sharedManager ] resumeAllActionsForTarget:sprite ] ;  

以下的每一個(gè)動(dòng)作,除了極為簡(jiǎn)單的,我都會(huì)加入一個(gè)簡(jiǎn)單的事例,以及描述下將會(huì)發(fā)生的情況。畢竟,都是物體移動(dòng),簡(jiǎn)單上圖片,很難表示清楚究竟發(fā)生了什么。尤其是那個(gè)jump函數(shù)。

簡(jiǎn)單應(yīng)用,對(duì)一個(gè)box精靈進(jìn)行移動(dòng)測(cè)試:

  1.  -(id)init{  
  2.     self = [super init];  
  3.     if(nil!=self){  
  4.         isTouchEnabled = YES;  
  5.         boxSprite = [Sprite spriteWithFile:@"box.png"];  
  6.         [boxSprite setPosition:CGPointMake(25, 25)];  
  7.         [self addChild:boxSprite];  
  8.     }  
  9.  
  10.     return self;  
  11. }  
  12.  
  13. - (BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *) event  
  14. {  
  15.     UITouch *touch = [touches anyObject];  
  16.     CGPoint point = [touch locationInView: [touch view]];  
  17.     //動(dòng)作的定義  
  18.     //position  
  19.     //MoveBy  
  20.     id moveByAction = [MoveBy actionWithDuration:2 position:ccp(30,50)];  
  21.     //動(dòng)作的執(zhí)行  
  22.     [boxSprite runAction:rotateByAction];  
  23.     return YES;  
  24. }  

基本的Actions

位置

  1. MoveBy   
  2. MoveTo   
  3. JumpBy   
  4. JumpTo   
  5. BezierBy   
  6. Place  

放大縮小

  1. ScaleBy   
  2. ScaleTo  

旋轉(zhuǎn)

  1. RotateBy   
  2. RotateTo  

顯示狀態(tài)

  1. Show   
  2. Hide   
  3. Blink   
  4. ToggleVisibility  

透明度

  1. FadeIn   
  2. FadeOut   
  3. FadeTo   
  4. RGB  
  5. TintBy   
  6. TintTo  

例子

有些動(dòng)作,還是需要自己實(shí)現(xiàn)了才知道函數(shù)是怎么個(gè)意思,對(duì)于e文的api,不如普通的那種順利,大多都是些C#里面少使用的東西。有些陌生。

  1. //MoveBy  
  2. moveByAction = [MoveBy actionWithDuration:2 position:ccp(30,50)];  

每次執(zhí)行,相應(yīng)精靈位置x,y增加30,和50,時(shí)間是2秒之內(nèi),移動(dòng)方式,緩慢移動(dòng)

  1. //MoveTo  
  2. id moveToAction = [MoveTo actionWithDuration:3 position:[[Director sharedDirector]convertCoordinate:point]];  

每次執(zhí)行,相應(yīng)精靈移動(dòng)到觸摸位置,3秒之內(nèi),移動(dòng)過(guò)去

  1. //JumpBy  
  2. jumpByAction = [JumpBy actionWithDuration:3 position:ccp(100,100) height:20 jumps:20];  

每次執(zhí)行,在3秒之內(nèi),相對(duì)移動(dòng)100,100,移動(dòng)方式,以20作為跳躍高度,3秒之內(nèi),20次跳躍

  1. //JumpTo  
  2. jumpToAction = [JumpTo actionWithDuration:3 position:ccp(100,100) height:20 jumps:20];  

使用方式,同上。不同的是移動(dòng)到100,100

  1. //BezierBy  
  2. bezierByAction = [BezierBy actionWithSize:2];   
  3. //ScaleBy  
  4. scaleByAction = [ScaleBy actionWithDuration:3 scaleX:0.5 scaleY:0.5];  

每次執(zhí)行,3秒之內(nèi),精靈逐漸變?yōu)樵瓉?lái)長(zhǎng)寬的一半

  1. //ScaleTo  
  2. scaleToAction = [ScaleTo actionWithDuration:3 scaleX:0.4 scaleY:0.5];   
  3. //RotateBy  
  4. rotateByAction = [RotateBy actionWithDuration:3 angle:30.0];  

3秒之內(nèi),逐漸向右旋轉(zhuǎn)30度。

  1.      //RotateTo  
  2. id rotateToAction = [RotateTo actionWithDuration:3 angle:30.0];   
  3.  
  4. CGSize s = [[Director sharedDirector] winSize];  
  5.  
  6. id actionTo = [MoveTo actionWithDuration: 2 position:ccp(s.width-40, s.height-40)];  
  7. id actionBy = [MoveBy actionWithDuration:2  position: ccp(80,80)];  
  8.  
  9. [sprite1 runAction: actionTo];  
  10. [sprite2 runAction:actionBy];  

回滾Actions

基本上都是以"reverse"開(kāi)頭的方法。就是實(shí)現(xiàn)某個(gè)Action的相反的動(dòng)作。

  1. id move = [MoveBy actionWithDuration:2  position: ccp(80,80)];  
  2. id move_reverse = [move reverse]; 

上面的move_reverse Action是指將MoveBy Action在2秒鐘移動(dòng)到ccp(-80,-80)的位置。

小結(jié):iPhone游戲開(kāi)發(fā)之Cocos2dActions介紹的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-08-11 14:22:47

iPhone游戲Cocos2D

2011-08-04 17:01:16

iPhone游戲開(kāi)發(fā) Cocos2d

2011-07-27 13:57:36

iPhone 游戲 Cocos2d

2011-07-27 10:13:23

Cocos2D iPhone

2011-07-27 17:07:06

iPhone 游戲 Cocos2d

2011-07-20 14:04:46

Cocos2d iPhone 游戲

2011-08-09 16:08:58

IOS游戲Cocos2d

2012-04-16 13:37:57

cocos2d

2011-07-27 14:48:21

iPhone Cocos2D 坐標(biāo)

2011-08-11 18:00:18

Cocos2d動(dòng)作Action

2011-08-08 11:26:39

Cocos2d 游戲 Class類

2011-08-22 10:49:42

Cocos2d 開(kāi)發(fā)CCLayerTouch事件

2012-02-19 20:10:23

Cocos2d-x fCocos2dWindows Pho

2011-08-02 15:37:48

Cocos2D UIAccelero

2011-08-11 17:52:01

Cocos2d游戲對(duì)象

2011-08-08 15:40:47

Cocos2d

2011-07-08 16:09:54

Cocoa Cocos2d 動(dòng)作

2012-06-01 10:27:44

Cocos2d觸摸分發(fā)原理

2011-07-08 16:27:52

Cocoa Cocos2d 動(dòng)作

2011-08-02 15:47:28

Cocos2D Animation
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)