iOS_31_cocos2d_訊息調度,ios_31_cocos2d調度
最終效果:
cocos2d V3 只要實現了- (void)update:(CCTime)delta方法,
就會自動調用它,無需手動調用
foreach 或者說for in遍曆的時侯,不能增刪成員
封裝的 子彈類,繼承自CCSprite
//// Bullet.h// 31_cocos2D入門//// Created by beyond on 14-9-7.// Copyright (c) 2014年 com.beyond. All rights reserved.// 子彈 成員屬性:速度 每秒移動多少#import "CCSprite.h"@interface Bullet : CCSprite// 速度(每秒挪動這個速度)@property (nonatomic, assign) CGPoint velocity;@end
//// Bullet.m// 31_cocos2D入門//// Created by beyond on 14-9-7.// Copyright (c) 2014年 com.beyond. All rights reserved.//#import "Bullet.h"@implementation Bullet// do nothing in cocos2d v3- (id)initWithTexture:(CCTexture *)texture rect:(CGRect)rect{<span style="white-space:pre"></span> if (self = [super initWithTexture:texture rect:rect]) { // 預設會調用update: // [self schedule:@selector(update:) interval:0]; // 取消訊息調度 // [self unschedule:<#(SEL)#>]; } return self;}// 路程 = 速度 * 時間// delta 兩次刷幀的時間間距- (void)update:(CCTime)delta{ // 每次增加5的x值 // self.position = ccpAdd(self.position, ccp(5, 0)); // s = 速度 * 時間 CGPoint deltaS = ccpMult(_velocity, delta); // 已變更位元置 self.position = ccpAdd(self.position, deltaS);}@end
主情境
//// HelloWorldScene.h// 31_cocos2D入門//// Created by beyond on 14-9-5.// Copyright com.beyond 2014年. All rights reserved.//// Importing cocos2d.h and cocos2d-ui.h, will import anything you need to start using Cocos2D v3#import "cocos2d.h"#import "cocos2d-ui.h"/** * 主情境 */@interface HelloWorldScene : CCScene+ (HelloWorldScene *)scene;- (id)init;@end
//// HelloWorldScene.m// 31_cocos2D入門//// Created by beyond on 14-9-5.// Copyright com.beyond 2014年. All rights reserved.//#import "HelloWorldScene.h"#import "IntroScene.h"#import "CCAnimation.h"// 子彈#import "Bullet.h"@implementation HelloWorldScene{ CCSprite *_sprite;}#pragma mark - 生命週期+ (HelloWorldScene *)scene{ return [[self alloc] init];}// 在HelloWorldScene中- (id)init{ if (!(self = [super init]) ) return(nil); // 1、情境Node 允許互動 self.userInteractionEnabled = YES; // 2、建立背景顏色為深灰色 CCNodeColor *background = [CCNodeColor nodeWithColor:[CCColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:1.0f]]; [self addChild:background]; // 3、添加一個精靈,並置中 [self addSpriteInCenter]; // 4、右上方,建立一個返回按鈕,點擊後,返回至上一個情境 [self addBtnOnTopRight]; // 5、重要,開啟訊息調用 // [self schedule:@selector(update:) interval:0]; // 返回建立好的情境對象return self;}#pragma mark - Enter & Exit//- (void)onEnter{ // 必須總是先調用父類的onEnter方法 [super onEnter]; // In pre-v3, touch enable and scheduleUpdate was called here // In v3, touch is enabled by setting userInteractionEnabled for the individual nodes // Per frame update is automatically enabled, if update is overridden }- (void)onExit{ // 必須總是 最後才調用父類的onExit方法 [super onExit];}#pragma mark - 觸摸事件// 使用者觸控螢幕幕,精靈跟隨手指移動-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint touchLoc = [touch locationInNode:self]; // 輸出觸摸點的座標 CCLOG(@"Move sprite to @ %@",NSStringFromCGPoint(touchLoc)); // 移動精靈到觸摸點處 To表示絕對 By表示相對 //CCActionMoveTo *actionMove = [CCActionMoveTo actionWithDuration:1.0f position:touchLoc]; // 調用精靈的runAction方法執行動作 //[_sprite runAction:actionMove];}// 手抬起處就放一顆bullet,並且讓子彈 射出去,並且進行碰撞檢測- (void)touchEnded:(UITouch *)touch withEvent:(UIEvent *)event{ // 得到觸摸點 CGPoint touchLoc = [touch locationInNode:self]; Bullet *bullet = [Bullet spriteWithImageNamed:@"bullet.png"]; bullet.name = @"bullet"; // 設定 子彈出現的位置 bullet.position = touchLoc; // 設定 子彈的速度 bullet.velocity = ccp(500, CCRANDOM_MINUS1_1() * 300); [self addChild:bullet];}// 在情境的訊息調度裡面,進行碰撞檢測- (void)update:(CCTime)delta{ [self boundaryCheck];}- (void)boundaryCheck{ for (int i = 0; i<self.children.count;i++) { CCSprite *child = [self.children objectAtIndex:i]; // 子彈 if ([child.name isEqualToString:@"bullet"]) { // 1.往右邊飛 // CGPoint pos = child.position; // pos.x += 5; // child.position = pos; // 2.跟人的碰撞檢測 // CCSprite *person = (CCSprite *)[self getChildByName:@"nana" recursively:YES]; if ( CGRectIntersectsRect(child.boundingBox, _sprite.boundingBox) ) { // 移除子彈 [child removeFromParentAndCleanup:YES]; CCLOG(@"碰到了人"); _sprite.opacity = _sprite.opacity*0.8; if (_sprite.opacity < 0.05) { _sprite.position = ccp(-10,-10); } } else if ( !CGRectContainsRect(self.boundingBox, child.boundingBox) ) { // 移除子彈 [child removeFromParentAndCleanup:YES]; CCLOG(@"離開了螢幕"); } } } }#pragma mark - 按鈕點擊事件- (void)onBackClicked:(id)sender{ // 使用轉場動畫,切換情境至 IntroScene [[CCDirector sharedDirector] replaceScene:[IntroScene scene] withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionRight duration:1.0f]];}#pragma mark - 私人方法// 右上方,建立一個返回按鈕,點擊後,返回至上一個情境- (void)addBtnOnTopRight{ // 5、右上方,建立一個返回按鈕,點擊後,返回至上一個情境 CCButton *backButton = [CCButton buttonWithTitle:@"[ Back ]" fontName:@"Verdana-Bold" fontSize:18.0f]; backButton.positionType = CCPositionTypeNormalized; // 螢幕的右上方 注意這裡是笛卡爾座標系,原點在左下方 backButton.position = ccp(0.85f, 0.95f); // 監聽點擊事件 [backButton setTarget:self selector:@selector(onBackClicked:)]; [self addChild:backButton];}// 添加一個精靈,並設定位置置中- (void)addSpriteInCenter{ // 3、添加一個精靈,並設定位置置中 ColorCircle _sprite = [CCSprite spriteWithImageNamed:@"nana_logo.png"]; _sprite.name = @"nana"; //NSString *fullPath = [[NSBundle mainBundle] pathForResource:@"nana_logo.png" ofType:nil]; //_sprite = [CCSprite spriteWithTexture:[CCTexture textureWithFile:fullPath ] rect:CGRectMake(0, 0, 112, 112) ]; //_sprite.position = ccp(self.contentSize.width/2,self.contentSize.height/2); _sprite.position = ccp(self.contentSize.width*0.85,self.contentSize.height/2); [self addChild:_sprite];}// 為精靈建立一個旋轉動作- (void)addRotateAction{ // 4、為精靈建立一個旋轉動作,並且調用精靈的runAction方法,重複執行動作 CCActionRotateBy* actionSpin = [CCActionRotateBy actionWithDuration:1.5f angle:360]; [_sprite runAction:[CCActionRepeatForever actionWithAction:actionSpin]];}// 測試sprite屬性- (void)testCCSprite{ _sprite.opacity = 125; //_sprite.color = [UIColor redColor];//ccc3(255, 0, 0); _sprite.color = [CCColor colorWithRed:1.0f green:0.2f blue:0.2f alpha:1.0f]; _sprite.flipX = YES; _sprite.flipY = YES; CCAction *action = [CCActionCallFunc actionWithTarget:self selector:@selector(go:)]; [_sprite runAction:action];}// 播放幀動畫【趙雲】- (void)playFrameAnimatiton{ // 建立精靈,並置中【千萬要記得addChild】 _sprite = [CCSprite spriteWithImageNamed:@"1.png"]; _sprite.position = ccp(self.contentSize.width/2,self.contentSize.height/2); // 用來存放所有的幀 NSMutableArray *frames = [NSMutableArray array]; // 載入所有的圖片 for (int i = 1; i<= 10; i++) { // 1、拼接圖片名 NSString *name = [NSString stringWithFormat:@"%i.png", i]; // 2、根據圖片名(或全路徑)產生紋理,一個圖片對應一個紋理對象 CCTexture *texture = [CCTexture textureWithFile:name]; CGRect retct = CGRectMake(0, 0, texture.contentSize.width, texture.contentSize.height); // 3、根據紋理建立一個精靈幀 CCSpriteFrame *frame = [[CCSpriteFrame alloc]initWithTexture:texture rectInPixels:retct rotated:NO offset:ccp(0, 0) originalSize:retct.size]; // 4、添加精靈幀 到 精靈幀數組中 [frames addObject:frame]; } // 根據【精靈幀數組】建立CCAnimation,參數:每隔0.1秒播放下一張圖片 CCAnimation *animation = [CCAnimation animationWithSpriteFrames:frames delay:0.1]; // 根據CCAnimation對象 建立 動作 CCActionAnimate *animate = [CCActionAnimate actionWithAnimation:animation]; CCActionRepeatForever *forever = [CCActionRepeatForever actionWithAction:animate]; [_sprite runAction:forever]; // 重要~~~必須成為情境的子Node [self addChild:_sprite];}@end
Windows訊息調度機制是
處理訊息佇列的順序。首先windows絕對不是按隊列先進先出的次序來處理的,而是有一定優先順序的。優先順序通過訊息佇列的狀態標誌來實現的。首先最高優先順序的是別的線程發過來的訊息(通過sendmessage),其次是處理登記訊息佇列訊息,再次處理QS_QUIT標誌,再處理虛擬輸入隊列,再處理wm_paint最後是wm_timer
參考資料:windows訊息機制 blog.csdn.net/...3.aspx
GSM有沒有系統訊息調度
發送位置SI5和SI6 SACCH,它並不重要的信令。
我不得不說,信令,即Imm.Ass(立即分配)。因為只有SACCH其後。