IOS_31_cocos2d _ message scheduling and ios_31_cocos2d Scheduling

Source: Internet
Author: User

IOS_31_cocos2d _ message scheduling and ios_31_cocos2d Scheduling

Final effect:



Cocos2d V3 only implements the-(void) update :( CCTime) delta method,

It is automatically called without manual calling.

During foreach or for in traversal, you cannot add or delete members.










The encapsulated bullet class inherited from CCSprite.

//// Bullet. h // 31_cocos2D getting started /// Created by beyond on 14-9-7. // Copyright (c) 2014 com. beyond. all rights reserved. // bullet member attribute: the speed of movement per second # import "CCSprite. h "@ interface Bullet: CCSprite // speed (moving this speed per second) @ property (nonatomic, assign) CGPoint velocity; @ end



//// Bullet. m // 31_cocos2D getting started /// 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]; // Cancel message scheduling // [self unschedule: <# (SEL) #>];} return self ;} // distance = speed * time // The time interval between two frames in delta-(void) update :( CCTime) delta {// increase the x value by 5 at a time // self. position = ccpAdd (self. position, ccp (5, 0); // s = speed * time CGPoint deltaS = ccpMult (_ velocity, delta); // change the position self. position = ccpAdd (self. position, deltaS) ;}@ end


Main scenarios



//// HelloWorldScene. h // 31_cocos2D getting started /// 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 "/*** main scenario */@ interface HelloWorldScene: CCScene + (HelloWorldScene *) scene;-(id) init; @ end





//// HelloWorldScene. m // 31_cocos2D getting started /// Created by beyond on 14-9-5. // Copyright com. beyond 2014. all rights reserved. // # import "HelloWorldScene. h "# import" IntroScene. h "# import" CCAnimation. h "// Bullet # import" Bullet. h "@ implementation HelloWorldScene {CCSprite * _ sprite;} # pragma mark-lifecycle + (HelloWorldScene *) scene {return [self alloc] init];} // In HelloWorldScene-(id) init {if (! (Self = [super init]) return (nil); // 1. Scene Node allows interaction with self. userInteractionEnabled = YES; // 2. The background color is dark gray. CCNodeColor * background = [CCNodeColor nodeWithColor: [CCColor colorWithRed: 0.2f green: 0.2f blue: 0.2f alpha: 1.0f]; [self addChild: background]; // 3. Add an Genie and center it in the center [self addSpriteInCenter]; // 4. Create a return button in the upper right corner, return to the first scenario [self addBtnOnTopRight]; // 5. Important: Enable message calling // [self schedule: @ selector (update :) int Erval: 0]; // return the created scenario object return self;} # pragma mark-Enter & Exit //-(void) onEnter {// always first call the onEnter method of the parent class [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 {// The onExit method of the parent class [super onExit] must always be called at the end;} # p Ragma mark-touch event // The user can touch the screen, and the genie follows the finger to move-(void) touchBegan :( UITouch *) touch withEvent :( UIEvent *) event {CGPoint touchLoc = [touch locationInNode: self]; // output the coordinate CCLOG of the touch point (@ "Move sprite to @ % @", NSStringFromCGPoint (touchLoc )); // move the genie To the touch point To indicate absolute By To indicate relative // CCActionMoveTo * actionMove = [CCActionMoveTo actionWithDuration: 1.0f position: touchLoc]; // call the runAction method of the genie to execute the action // [_ sprite runAction: actionMove];} // Put a bullet when you hold your hand up, and let the bullet go, and perform Collision Detection-(void) touchEnded :( UITouch *) touch withEvent :( UIEvent *) event {// obtain the touch point CGPoint touchLoc = [touch locationInNode: self]; Bullet * bullet = [Bullet spriteWithImageNamed: @ "bullet.png"]; bullet. name = @ "bullet"; // set the position where the bullet appears. position = touchLoc; // set the speed of the bullet. velocity = ccp (500, CCRANDOM_MINUS1_1 () * 300); [self addChild: bullet];} // perform collision detection (voi D) 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. fly to the right // CGPoint pos = child. position; // pos. x + = 5; // child. position = pos; // 2. human collision detection // CCSprite * person = (CCSprite *) [self getChildByName: @ "nana" recursively: YES]; if (C GRectIntersectsRect (child. boundingBox, _ sprite. boundingBox) {// remove the bullet [child removeFromParentAndCleanup: YES]; CCLOG (@ "met"); _ sprite. opacity = _ sprite. opacity * 0.8; if (_ sprite. opacity <0.05) {_ sprite. position = ccp (-10,-10) ;}} else if (! CGRectContainsRect (self. boundingBox, child. boundingBox) {// remove the bullet [child removeFromParentAndCleanup: YES]; CCLOG (@ "Exit screen") ;}}# pragma mark-click the event-(void) onBackClicked :( id) sender {// use the transition animation. Switch the scene to IntroScene [[CCDirector sharedDirector] replaceScene: [IntroScene scene] withTransition: [CCTransition duration: Transition duration: 1.0f];} # pragma mark-Private method // upper right corner, Create a return button, click, return to the first scenario-(void) addBtnOnTopRight {// 5, in the upper right corner, create a return button, click, return to the previous scenario CCButton * backButton = [CCButton buttonWithTitle: @ "[Back]" fontName: @ "Verdana-Bold" fontSize: 18366f]; backButton. positionType = CCPositionTypeNormalized; // in the upper-right corner of the screen, note that the Cartesian coordinate system is used. The origin is in the backButton at the lower-left corner. position = ccp (0.85f, 0.95f); // listen to the click event [backButton setTarget: self selector: @ selector (onBackClicked :)]; [self addChild: backBut Ton];} // Add a sprite and set the location Center-(void) addSpriteInCenter {// 3. Add a sprite and set the location Center 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];} // create a rotation action for the genie-(void) addRotateAction {// 4. Create a rotation action for the genie, call the runAction method of the genie and execute the CCActionRotateBy * actionSpin = [CCActionRotateBy actionWithDuration: 1.5f angle: 360]; [_ sprite runAction: [CCActionRepeatForever actionWithAction: actionSpin] // test the sp Rite property-(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];} // play the Frame Animation [Zhao Yun]-(void) playFrameAnimatiton {// create a genie and center it [remember to add Child] _ sprite = [CCSprite spriteWithImageNamed: @ "1.png"]; _ sprite. position = ccp (self. contentSize. width/2, self. contentSize. height/2); // used to store all frames NSMutableArray * frames = [NSMutableArray array]; // load all images for (int I = 1; I <= 10; I ++) {// 1. name of the spliced image NSString * name = [NSString stringWithFormat: @ "ii.png", I]; // 2. Based on the image name (or full path) generate a texture. An Image corresponds to a texture object CCTexture * texture = [CCTexture textureWithFile: name]; CGR Ect retct = CGRectMake (0, 0, texture. contentSize. width, texture. contentSize. height); // 3. Create a Sprite frame based on the texture. CCSpriteFrame * frame = [[CCSpriteFrame alloc] initWithTexture: texture rectInPixels: retct rotated: NO offset: ccp (0, 0) originalSize: retct. size]; // 4. Add the sprite frame to the number of Sprite frames group [frames addObject: frame];} // create a CCAnimation based on the number of Sprite frames group. parameter: play the next image every 0.1 seconds. CCAnimation * animation = [CCAnimation animationWithSpriteFrames: f Rames delay: 0.1]; // create an action CCActionAnimate * animate = [CCActionAnimate actionWithAnimation: animation] based on the CCAnimation object; then * forever = [Your actionWithAction: animate]; [_ sprite runAction: forever]; // important ~~~ Must be a subnode of the scenario [self addChild: _ sprite];} @ end













The message scheduling mechanism in Windows is

The order in which message queues are processed. First of all, windows does not process queues in the FIFO order, but has a certain priority. Priority is achieved by the Status mark of the message queue. The highest priority is the messages sent by other threads (via sendmessage), the second is to register the Message Queue message, process the QS_QUIT mark again, and then process the virtual input queue, then wm_paint is processed and wm_timer is final.
Reference: windows message mechanism blog.csdn.net/...3.aspx

Does GSM have system message scheduling?

The sending locations SI5 and SI6 SACCH, which are not important signaling.
I have to say, signaling, that is, Imm. Ass (allocated immediately ). Because only after the SACCH.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.