[一位菜鸟的COCOS-2D编程之路]COCOS2D基础知识-CCScene

接着上次的基础知识,我们今天讲解后面的知识点

1.CCscene 场景 ,这个类主要是说明和场景切换有关的类

  • 创建、初始化一个场景

  //1)创建一个 场景切换的类
        //初始化或者创建一个一个场景
    
        CCTransitionScene *transitionScene = [CCTransitionScene transitionWithDuration:4 scene:newScene];
            [transitionScene initWithDuration:1 scene:newScene];

  • 场景过渡效果结束
    //2过渡效果结束的时候使用
            [transitionScene finish];

  •  //3部分过渡效果会使用该方法隐藏更外层的场景
            [transitionScene hideOutShowIn];
        //一个实例
  • 这是关于一个场景的延迟出现。
       ///** creates a base transition with duration and incoming scene */
           // +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s;

 2。CCLayer
//2CCLayer类的使用
        //1)作用   其他子节点的的容器和组织者
        //2 接受触摸事件
        self.isTouchEnabled = YES;
        //3 接受加速器事件
        self.isAccelerometerEnabled = YES;
        //同样,我们层里需要加入一个特定的方法来接受加速计事件
        
        //4CCLayerColor色彩层
        //可以设置RGB颜色的层,试下 CCRGBAprotocol协议的CCLayer子类
        //1)CCLayerColor的属性 color,opacity透明度,blendFunc.混合模式
        //2)CClayerColor类的方法。
        ccColor4F c4f = ccc4f(100, 100, 100, 100);
        ccColor4B c4b = ccc4BFromccc4F(c4f);
        //
        CCLayerColor *layerColor = [[CCLayerColor alloc]init];
        //初始化方法
         CCLayerColor *layerColor1 = [[CCLayerColor alloc]initWithColor:c4b];
        //初始化一个带长宽的色彩层
        CCLayerColor *layerColor2 =[[CCLayerColor alloc]initWithColor:c4b width: 100 height:100];
        [layerColor2 changeHeight:10];
        [layerColor2 changeWidth:22];
        [layerColor2 changeWidth:10 height:22];
        
        //5 CCLayerGrdient 渐变色层
        //是CClayerColor的子类,继承了其所有的属性,增加了渐变方向,插值模式
        //初始化一个特定渐变效果的色彩层
        
        CCLayerGradient *gradient = [[CCLayerGradient alloc]initWithColor:c4b fadingTo:c4b:ccp(0, -1)];
        
        //6CCMenu菜单类  MenuItem 类实例组成各种按钮
        
    //CCmenuItem 子类如下:
       // 1)CCmenuItemLabel  点击具有放大效果 iCCLabelBMFont ii:CCLabelAtlas,CCLabelTTF
      
        CCLabelBMFont *label1 = [CCLabelBMFont labelWithString:@"Seeting" fntFile:@"font1.fnt"];
        CCMenuItemLabel *item1 = [CCMenuItemLabel itemWithLabel:label1 target:self selector:nil];
        
        
        //2)CCMenuItemAtlasFont,CCmenuItemSprite,CCMenuItemImage,CCMenuItemToggle
        //7CCTexture 纹理类
        //1)纹理 Texture,2)纹理图集 TextureAylas
        //3纹理的三种方式
        //iCCTextureCache 单例使用,用于加载和管理纹理
        NSString *filename = @"hell.png";
        CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:filename];
        //ii:CCTextureAtlas
        //8.CCSprite
        CCSprite *sprite = [CCSprite spriteWithFile:filename];
        //1.)纹理集的索引
        [sprite setAtlasIndex:1];//通常不建议修改
        //2对渲染CCSprite 的CCSpriteBatchNode的弱引用
        //[sprite setBatchNode:<#(CCSpriteBatchNode *)#>]
        //3 blendFunc 遵循CCtextureProtocol协议
        //4 color:RGB颜色 遵循CCRGBAProtocol协议
        //5dirty:判断精灵是否需要在纹理集中更新
        //6 filpx:判断精灵是否会沿水平方向旋转
         //7 filpy
        //8  offsetPosition 以点值计量精灵位置的偏移
        //9 opacticy 透明度
     //等
       //9。精灵的类方法
       //很多都是初始化方法,不再赘述
        //10 CCSpriteBatchNode  精灵表单需要 OPENGL ES 一次性处理所有的纹理图,减少GPU的压力
        //精灵表单的三种方法
        //1.初始化一个精灵表单,可以最多容纳 29*1.33
        CCSpriteBatchNode *sprites = [CCSpriteBatchNode batchNodeWithFile:filename];
        CCSpriteBatchNode *sprites2 = [CCSpriteBatchNode batchNodeWithFile:filename capacity:12];
        //CCSpriteBatchNode *sprite3 = [[CCSpriteBatchNode batchNodeWithTexture:[CCTexture2D alloc]];
        //2。移除一个子精灵,由于操作速度很慢,不建议使用
      //  [sprites removeChild:one cleanup:YES];

3.重启游戏的场景切换
- (void)onRestartGame
{
    CCTransitionFade *tramsitionFade = [CCTransitionFade transitionWithDuration:3 scene:[HelloWorldLayer scene] withColor:ccWHITE];
    //重新开游戏的时候使用白色作为过度场景。 当然,除了 fade,还有很多别的过度场景
    
    //使用过度场景对象替代helloworld场景,作为中间过渡场景,也就是延迟helloWorldLyer场景的出现
    [[CCDirector sharedDirector]replaceScene:tramsitionFade];


}

4.加速计的使用
#pragma  mark 如何操作加速计
/*
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    float deceleration = 0.4f;
    float sensitivity = 6.0f;
    
    float maxVelocity = 100;
    
    _playerVelocity.x =_playerVelocity.x *deceleration + acceleration.x *sensitivity;
    
    if (_playerVelocity.x > maxVelocity)
        _playerVelocity.x = maxVelocity;
    else if(_playerVelocity.x < -maxVelocity)
        _playerVelocity.x = -maxVelocity;
    
    
}

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值