注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

熊猫正正的博客

熊猫正正的天空

 
 
 

日志

 
 

cocos2d-组合动作  

2013-06-05 20:36:03|  分类: ios游戏开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

- (id) init

{

    self = [super init];

    if (self)

    {

        CGSize size = [CCDirector sharedDirector].winSize;

        

        CCSprite *sp = [CCSprite spriteWithFile:@"Space.png"];

        sp.opacity = 100;

        sp.position = ccp(size.width/2,size.height/2);

        sp.rotation = 90;

        

        [self addChild:sp z:0 tag:1];

        

        [CCMenuItemFont setFontName:@"Arial"];

        [CCMenuItemFont setFontSize:18];

        

        CCMenuItem *SeqMenu = [CCMenuItemFont itemWithString:@"Sequence" target:self selector:@selector(OnSequence:)];

        CCMenuItem *SpwMenu = [CCMenuItemFont itemWithString:@"Spawn" target:self selector:@selector(OnSpawn:)];

        CCMenuItem *RepMenu = [CCMenuItemFont itemWithString:@"Repeat" target:self selector:@selector(OnRepeat:)];

        CCMenuItem *RevMenu = [CCMenuItemFont itemWithString:@"Revers" target:self selector:@selector(OnReverse:)];

        CCMenuItem *AniMenu = [CCMenuItemFont itemWithString:@"Animation" target:self selector:@selector(OnAnimation:)];

        CCMenuItem *RepForMenu = [CCMenuItemFont itemWithString:@"RepeatForever" target:self selector:@selector(OnRepeatForever:)];

        

        CCMenuItem *backMenu = [CCMenuItemFont itemWithString:@"Back" target:self selector:@selector(OnBackMenu:)];

        

        CCMenu *menu = [CCMenu menuWithItems:SeqMenu,SpwMenu,RepMenu,RevMenu,AniMenu,RepForMenu,backMenu, nil];

        

        [menu alignItemsVertically];

        menu.position = ccp(60,menu.position.y);

        

        [self addChild:menu z:1 tag:2];

        

        CCSpriteBatchNode *mgr = [CCSpriteBatchNode batchNodeWithFile:@"flight.png" capacity:5];

        [self addChild:mgr z:0 tag:4];

        

        sprite = [CCSprite spriteWithTexture:mgr.texture rect:CGRectMake(32*2, 0, 31, 30)];

        [mgr addChild:sprite z:1 tag:5];

        

        sprite.scale = 2.0;

        sprite.position = ccp(size.width/2,50);

    }

    

    return self;

}


- (void) OnAnimation: (id) sender

{

    CCSpriteBatchNode *mgr = (CCSpriteBatchNode*)[self getChildByTag:4];

    NSMutableArray *frames = [[NSMutableArray alloc] initWithCapacity:3];

    for (int i = 0 ; i < 3 ; i++)

    {

        int x = i % 3;

        CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:mgr.texture rect:CGRectMake(x*32, 0, 31, 30)];

        [frames addObject:frame];

    }

    

    CCAnimation *animation = [CCAnimation animationWithSpriteFrames:frames delay:0.2f];

    id action = [CCAnimate actionWithAnimation:animation];

    [sprite runAction:[CCRepeat actionWithAction:action times:10]];

}


- (void) OnSequence: (id) sender

{

    CGSize size = [CCDirector sharedDirector].winSize;

    CGPoint p = ccp(size.width/2,50);

    

    id ac0 = [sprite runAction:[CCPlace actionWithPosition:p]];

    id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(size.width - 50,size.height - 50)];

    id ac2 = [CCJumpTo actionWithDuration:2 position:ccp(150,50) height:30 jumps:5];

    id ac3 = [CCBlink actionWithDuration:2 blinks:3];

    id ac4 = [CCTintBy actionWithDuration:0.5 red:0 green:255 blue:255];

    

    [sprite runAction:[CCSequence actions:ac0,ac1,ac2,ac3,ac4, nil]];

}


- (void) OnSpawn: (id) sender

{

    CGSize size = [CCDirector sharedDirector].winSize;

    CGPoint p = ccp(size.width/2,50);

    sprite.rotation = 0;

    [sprite setPosition:p];

    

    id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(size.width - 50,size.height - 50)];

    id ac2 = [CCRotateTo actionWithDuration:2 angle:180];

    id ac3 = [CCScaleTo actionWithDuration:1 scale:4];

    id ac4 = [CCScaleBy actionWithDuration:1 scale:0.5];

    

    id seq = [CCSequence actions:ac3,ac4, nil];

    

    [sprite runAction:[CCSpawn actions:ac1,ac2,seq, nil]];

}


- (void) OnRepeat: (id) sender

{

    CGSize size = [CCDirector sharedDirector].winSize;

    CGPoint p = ccp(size.width/2,50);

    

    sprite.rotation = 0;

    [sprite setPosition:p];

    

    id ac1 = [CCMoveTo actionWithDuration:2 position:ccp(size.width - 50,size.height - 50)];

    id ac2 = [CCJumpBy actionWithDuration:2 position:ccp(-400,-200) height:30 jumps:5];

    id ac3 = [CCJumpBy actionWithDuration:2 position:ccp(size.width/2,0) height:20 jumps:3];

    

    id seq = [CCSequence actions:ac1,ac2,ac3,nil];

    [sprite runAction:[CCRepeat actionWithAction:seq times:3]];

}


- (void) OnReverse: (id) sender

{

    CGSize s = [CCDirector sharedDirector].winSize;

    CGPoint p = ccp(s.width/2,50);

    

    sprite.rotation = 0;

    [sprite setPosition:p];

    

    id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(190,220)];

    id ac2 = [ac1 reverse];

    

    [sprite runAction:[CCRepeat actionWithAction:[CCSequence actions:ac1,ac2,nil] times:2]];

}


- (void) OnRepeatForever: (id) sender

{

    CGSize s = [CCDirector sharedDirector].winSize;

    CGPoint p = ccp(100,50);

    

    CCSpriteBatchNode *mgr = (CCSpriteBatchNode*)[self getChildByTag:4];

    NSMutableArray *frames = [[NSMutableArray alloc] init];

    

    for ( int i = 0 ; i < 3 ; i++)

    {

        int x = x % 3;

        CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:mgr.texture rect:CGRectMake(x*32, 0, 31, 30)];

        [frames addObject:frame];

    }

    

    CCAnimation *animation = [CCAnimation animationWithSpriteFrames:frames delay:0.1f];

    id action = [CCAnimate actionWithAnimation:animation];

    

    [sprite runAction:[CCRepeatForever actionWithAction:action]];

    

    ccBezierConfig bezier;

    sprite.rotation = 0;

    [sprite setPosition:p];

    

    bezier.controlPoint_1 = ccp(0,s.height/2);

    bezier.controlPoint_2 = ccp(300,-s.height/2);

    bezier.endPosition = ccp(300,100);

    

    

    id ac10 = [CCBezierBy actionWithDuration:3 bezier:bezier];

    id ac11 = [CCTintBy actionWithDuration:0.5 red:0 green:255 blue:255];

    

    id ac1 = [CCSpawn actions: ac10,[CCRepeat actionWithAction:ac11 times:4],nil];

    id ac2 = [CCSpawn actions: [ac10 reverse],[CCRepeat actionWithAction:ac11 times:4],nil];

    

    [sprite runAction:[CCRepeatForever actionWithAction:[CCSequence actions:ac1,ac2,nil]]];

    

/*

id ac2 = [JumpBy actionWithDuration:2 position:ccp(-400, -200) height:30 jumps:5];

id ac3 = [JumpBy actionWithDuration:2 position:ccp(s.width/2, 0) height:20 jumps:3];

 

id seq = [Sequence actions:ac1, ac2, ac3, nil];

 

[sprite runAction:[Repeat actionWithAction:seq times:3]];

*/

}


- (void) OnBackMenu: (id) sender

{

    [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInL transitionWithDuration:1.2f scene:[HelloWorldLayer scene]]];

}


- (void) dealloc

{

    [super dealloc];

}


  评论这张
 
阅读(108)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017