99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

了解CCMoveToCCCallFuncNCCSequence用法-創新互聯

在《iPhone & iPad Cocos2D游戲開發實戰》一書中在看第四章時候遇到陌生知識,然后在網上找到相關知識點,再此記錄;

成都創新互聯服務項目包括鳳泉網站建設、鳳泉網站制作、鳳泉網頁制作以及鳳泉網絡營銷策劃等。多年來,我們專注于互聯網行業,利用自身積累的技術優勢、行業經驗、深度合作伙伴關系等,向廣大中小型企業、政府機構等提供互聯網行業的解決方案,鳳泉網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到鳳泉省份的部分城市,未來相信會繼續擴大服務區域并繼續獲得客戶的支持與信任!

由序列控制蜘蛛的移動方法代碼

-(void) runSpiderMoveSequence:(CCSprite*)spider { // 隨著時間慢慢增加蜘蛛的移動速度  numSpidersMoved++;//定義的int型變量 if (numSpidersMoved % 8 == 0 && spiderMoveDuration > 2.0f) { spiderMoveDuration -= 0.1f; } // 用于控制蜘蛛移動的動作序列 CGPoint belowScreenPosition = CGPointMake(spider.position.x, -[spider texture].contentSize.height); CCMoveTo* move = [CCMoveTo actionWithDuration:spiderMoveDuration position:belowScreenPosition]; CCCallFuncN* call = [CCCallFuncN actionWithTarget:self selector:@selector(spiderBelowScreen:)]; CCSequence* sequence = [CCSequence actions:move, call, nil]; [spider runAction:sequence];  }

RunSpiderMoveSequence方法的作用是跟蹤已被放下的蜘蛛數量。每次到第八個蜘蛛時,spiderMoveDuration的值就會被減少,從而提高所有蜘蛛的移動速度。%這個符號叫作“余數運算子”(Modulus Operator),用于得到運用除法以后得到的余數。比如,如果numSpidersMoved可以用8除盡,那么“余數運算子”的計算結果就應該是0。

這里用到的動作序列只有一個CCMoveTo動作和一個CCCallFuncN動作。你可以改進蜘蛛的行為,比如讓它往下移動一點,等個幾秒鐘,然后一直移動到底部,就像真的邪惡的蜘蛛通常會做的那樣。我將把具體的做法留給你去發揮。我選擇CCCallFuncN的目的是給spiderBelowScreen方法傳遞蜘蛛精靈作為它的sender變量。這樣的話,當某只蜘蛛到達屏幕底部時,我就可以直接引用那個蜘蛛,不需要再去到處找了

1.CCMoveTo

表示移動到某一個點,還有一個與它類似的CCMoveBy表示移動相對于當前位置某個位置,相當于一個向量;

2.CCCallFuncN

CCCallFuncN 帶有一個參數,這個參數本身是一個Action,相當于他的參數就是一個BUtton;與它類似的還有

CCCallFunc 不帶參數, 執行回調函數方法,

CCCallFuncND 帶兩個參數,一個是Action動作,另一個是自定義的參數

CCCallFuncO 也是兩個參數,和CCCallFuncN參數一樣,


以下是幾個類在CCActionInstant.m文件中的定義,通過他們的-(void)execute函數看出他們參數問題

// // CallFunc // #pragma mark CCCallFunc  @implementation CCCallFunc  @synthesize targetCallback = targetCallback_;  +(id) actionWithTarget: (id) t selector:(SEL) s { 	return [[[self alloc] initWithTarget: t selector: s] autorelease]; }  -(id) initWithTarget: (id) t selector:(SEL) s { 	if( (self=[super init]) ) { 		self.targetCallback = t; 		selector_ = s; 	} 	return self; }  -(NSString*) description { 	return [NSString stringWithFormat:@"<%@ = %p | Tag = %ld | selector = %@>", 			[self class], 			self, 			(long)tag_, 			NSStringFromSelector(selector_) 			]; }  -(void) dealloc { 	[targetCallback_ release]; 	[super dealloc]; }  -(id) copyWithZone: (NSZone*) zone { 	CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_]; 	return copy; }  -(void) update:(ccTime)time { 	[self execute]; }  -(void) execute { 	[targetCallback_ performSelector:selector_]; } @end
 // // CallFuncN // #pragma mark CCCallFuncN  @implementation CCCallFuncN  -(void) execute { 	[targetCallback_ performSelector:selector_ withObject:target_]; } @end
 // // CallFuncND // #pragma mark CCCallFuncND  @implementation CCCallFuncND  @synthesize callbackMethod = callbackMethod_;  +(id) actionWithTarget:(id)t selector:(SEL)s data:(void*)d { 	return [[[self alloc] initWithTarget:t selector:s data:d] autorelease]; }  -(id) initWithTarget:(id)t selector:(SEL)s data:(void*)d { 	if( (self=[super initWithTarget:t selector:s]) ) { 		data_ = d;  #if COCOS2D_DEBUG 		NSMethodSignature * sig = [t methodSignatureForSelector:s]; // added 		NSAssert(sig !=0 , @"Signature not found for selector - does it have the following form? -(void)name:(id)sender data:(void*)data"); #endif 		callbackMethod_ = (CC_CALLBACK_ND) [t methodForSelector:s]; 	} 	return self; }  -(id) copyWithZone: (NSZone*) zone { 	CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_ data:data_]; 	return copy; }  -(void) dealloc { 	// nothing to dealloc really. Everything is dealloc on super (CCCallFuncN) 	[super dealloc]; }  -(void) execute { 	callbackMethod_(targetCallback_,selector_,target_, data_); } @end
 @implementation CCCallFuncO @synthesize  object = object_;  +(id) actionWithTarget: (id) t selector:(SEL) s object:(id)object { 	return [[[self alloc] initWithTarget:t selector:s object:object] autorelease]; }  -(id) initWithTarget:(id) t selector:(SEL) s object:(id)object { 	if( (self=[super initWithTarget:t selector:s] ) ) 		self.object = object;  	return self; }  - (void) dealloc { 	[object_ release]; 	[super dealloc]; }  -(id) copyWithZone: (NSZone*) zone { 	CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_ object:object_]; 	return copy; }   -(void) execute { 	[targetCallback_ performSelector:selector_ withObject:object_]; }  @end

3.CCSequence

sequence是用來按順序執行一系列的動作,即動作按排列的順序一個接一個的執行,示例如下:

id action1 = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id action2 = [CCMoveBy actionWithDuration:2  position: ccp(80,80)]; id action3 = [CCMoveBy actionWithDuration:2  position: ccp(0,80)]; [sprite runAction: [CCSequence actions:action1, action2, action3, nil]];

上面這段代碼的意思是,sprite(精靈對象)先移動到坐標(100,100)位置,然后在向右上方移動(80,80),然后,再向右移動80(80,0)。這一系列動作是不重疊,一個接一個的執行的。

注意的是,在這些動作中不能有 CCRepeatForever 這種無限的動作(就是不停的一直持續的動作),必須是那種可以在有限的時間內完成的。

另外在博客上看到其他幾個類似的類的用法,都是cocos2d常用動作 原文連接 http://leeyin.iteye.com/blog/1306557

CCSpawn

這個與上面的 CCSequence 不同的是,排列的動作是同時執行的,執行的時間以子動作中的最長的時間為準。代碼示例:

id action = [CCSpawn actions: 		[CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4], 		[CCRotateBy actionWithDuration: 2 angle: 720], 		nil];   [sprite runAction:action];

上面這段代碼的意思是,sprite 在兩秒鐘內,向右跳四次,總共跳躍距離是300,跳躍高度是50,在跳躍過程中 同時旋轉720度。

CCRepeat

這個是用來重復一個動作有限的次數。當然,你也可以用CCSequence來實現同樣的功能,只是那樣看起來有點傻。示例:

id a1 = [CCMoveBy actionWithDuration:1 position:ccp(150,0)]; id action1 = [CCRepeat actionWithAction: 		[CCSequence actions: [CCPlace actionWithPosition:ccp(60,60)], a1, nil] 		times:3]; [sprite runAction:action1];

上面這段代碼的意思是,先將sprite 放置在(60,60)位置,然后一秒內向右移動150的距離。這兩個動作重復3次。

CCRepeatForever

上面的是重復有限次數,這個是無限次重復,比如,你想讓一個輪子不停的旋轉,就可以用這個實現。示例:

CCRotateBy* rotate = [CCRotateBy actionWithDuration:1.0f angle:360]; CCRepeatForever* action2 = [CCRepeatForever actionWithAction:rotate]; [sprite runAction:action2];

就像上面講的這段代碼會讓這個 sprite 一直不停的 以每秒360度的轉速永遠的旋轉下去。 

另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網站標題:了解CCMoveToCCCallFuncNCCSequence用法-創新互聯
網頁URL:http://www.yijiale78.com/article36/ceessg.html

成都網站建設公司_創新互聯,為您提供網站營銷手機網站建設網站收錄小程序開發云服務器自適應網站

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網站建設