cocos2d 总结:二scenes and layers

scenes and layers

 

1:显示的第一个场景 runWithScene

[[CCDirector sharedDirector] runWithScene:[FirstScene scene]];

 

2:场景转换 replaceScene

1)有转换效果

    CCSlideInBTransition* transition = [CCSlideInBTransition transitionWithDuration:3 scene:[OtherScene scene]];

    [[CCDirector sharedDirector] replaceScene:transition];

 

或者

[[CCDirector sharedDirector] replaceScene:[FirstScene scene]];

 

 

 

3:cocos2d的日志输出   参数的个数由,第一个参数%@的个数制定 @"%@: %@",

      CCLOG(@"===========================================");

    CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);

4:断言

NSAssert([layer isKindOfClass:[GameLayer class]], @"%@: not a GameLayer!", NSStringFromSelector(_cmd));

如果([layer isKindOfClass:[GameLayer class]] false,显示提示信息

 

5:CCColorLayer

CCColorLayer* colorLayer = [CCColorLayer layerWithColor:ccc4(255, 0, 255, 255)];

 

5:取得一个CCSprite的矩形

CGRect rect [spiderSprite boundingBox];

 

7:用图片创建一个进度条

 

CCProgressTimer* timer = [CCProgressTimer progressWithFile:@"firething.png"];

       timer.type = kCCProgressTimerTypeRadialCCW;

       timer.position = CGPointMake(32, screenSize.height - 32);

              //设置当前值

       timer.percentage = 0;

       [self addChild:timer z:1 tag:UILayerTagProgressTimer];

 

// The update is needed for the progress timer.

[self scheduleUpdate];

 

 

// Updates the progress timer

-(void) update:(ccTime)delta

{

CCNode* node = [self getChildByTag:UILayerTagProgressTimer];

NSAssert([node isKindOfClass:[CCProgressTimer class]], @"node is not a CCProgressTimer");

CCProgressTimer* timer = (CCProgressTimer*)node;

timer.percentage += delta * 10;

if (timer.percentage >= 100)

{

timer.percentage = 0;

}

}


 

 

 

8: CCParallaxNode

 

       CGSize screenSize = [[CCDirector sharedDirector] winSize];

      

       // Load the sprites for each parallax layer, from background to foreground.

       CCSprite* para1 = [CCSprite spriteWithFile:@"parallax1.png"];

       CCSprite* para2 = [CCSprite spriteWithFile:@"parallax2.png"];

       CCSprite* para3 = [CCSprite spriteWithFile:@"parallax3.png"];

       CCSprite* para4 = [CCSprite spriteWithFile:@"parallax4.png"];

 

       // Set the correct offsets depending on the screen and image sizes.

       para1.anchorPoint = CGPointMake(0, 1);

       para2.anchorPoint = CGPointMake(0, 1);

       para3.anchorPoint = CGPointMake(0, 0.6f);

       para4.anchorPoint = CGPointMake(0, 0);

       CGPoint topOffset = CGPointMake(0, screenSize.height);

       CGPoint midOffset = CGPointMake(0, screenSize.height / 2);

       CGPoint downOffset = CGPointZero;

 

       // Create a parallax node and add the sprites to it.

       CCParallaxNode* paraNode = [CCParallaxNode node];

       [paraNode addChild:para1 z:1 parallaxRatio:CGPointMake(0.5f, 0) positionOffset:topOffset];

       [paraNode addChild:para2 z:2 parallaxRatio:CGPointMake(1, 0) positionOffset:topOffset];

       [paraNode addChild:para3 z:4 parallaxRatio:CGPointMake(2, 0) positionOffset:midOffset];

       [paraNode addChild:para4 z:3 parallaxRatio:CGPointMake(3, 0) positionOffset:downOffset];

       [self addChild:paraNode z:0 tag:ParallaxSceneTagParallaxNode];

 

9:CCLayer的默认事件处理级别为 addStandardDelegate,可以在CCLayer的子类中重写 registerWithTouchDispatcher,改变事件处理级别

 

-(void) registerWithTouchDispatcher

{

    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];

}

 

10: CCRibbon------???

-(void) resetRibbon

 

你可能感兴趣的:(cocos2d)