CCSprite各种动作介绍和使用

CCSprite各种动作介绍和使用

 

 

// 触摸屏
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    for( UITouch *touch in touches ) {
		CGPoint location = [touch locationInView: [touch view]];
		location = [[CCDirector sharedDirector] convertToGL: location];

        // 各种动作
        
        // 瞬时动作
        // 设置坐标
        id action0 = [CCPlace actionWithPosition:ccp(240,160)];
        // 隐藏
        id action1 = [CCHide action];
        // 显示
        id action2 = [CCShow action];
        // 隐藏/显示
        id action3 = [CCToggleVisibility action];
        
        // 延时动作
        // 移动
        id action4 = [CCMoveTo actionWithDuration:2 position:ccp(0,0)];
        id action5 = [CCMoveBy actionWithDuration:2 position:ccp(100,100)];
        // 弹跳
        id action6 = [CCJumpTo actionWithDuration:2 position:ccp(0,200) height:30 jumps:5];
        id action7 = [CCJumpBy actionWithDuration:2 position:ccp(100, 0) height:30 jumps:5];
        // 贝塞尔移动
        ccBezierConfig bezier;
        bezier.controlPoint_1 = ccp(0, 0);
        bezier.controlPoint_2 = ccp(100, 300);
        bezier.endPosition = ccp(0,100);
        id action8 = [CCBezierTo actionWithDuration:3 bezier:bezier];
        id action9 = [CCBezierBy actionWithDuration:3 bezier:bezier];
        // 缩放
        id action10 = [CCScaleTo actionWithDuration:2 scale:4];
        id action11 = [CCScaleBy actionWithDuration:2 scale:0.5];
        // 旋转
        id action12 = [CCRotateTo actionWithDuration:2 angle:180];
        id action13 = [CCRotateBy actionWithDuration:2 angle:-180];
        // 闪烁
        id action14 = [CCBlink actionWithDuration:3 blinks:5];
        // 色调变化
        id action15 = [CCTintTo actionWithDuration:2 red:255 green:0 blue:0];
        id action16 = [CCTintBy actionWithDuration:0.5 red:0 green:255 blue:255];
        // 淡化到/淡入/淡出
        id action17 = [CCFadeTo actionWithDuration: 1 opacity:80];
        id action18 = [CCFadeIn actionWithDuration:1.0f];
        id action19 = [CCFadeOut actionWithDuration:1.0f];
        
        // 动画顺序播放
        CCAnimation *animation = [CCAnimation animation];
        [animation setDelay:2];
        // 这里就添加两帧,需要自己添加
        [animation addFrameWithTexture:sprTest.texture rect:CGRectMake(0, 0, 44, 34)];
        [animation addFrameWithTexture:sprTest.texture rect:CGRectMake(0, 34, 44, 34)]; 
        id action20 = [CCAnimate actionWithAnimation: animation];
        
        // 组合动作
        // 动画序列
        id action21 = [CCSequence actions:action19, action18, nil];
        // 重复动作
        id action22 = [CCRepeat actionWithAction:action21 times:10];
        // 延时动作
        id action23 = [CCDelayTime actionWithDuration:1];
        // 同时动作
        id action24 = [CCSpawn actions:action0, action4, action21, nil];
        // 无限循环动作
        id action25 = [CCRepeatForever actionWithAction:action21];
        
        // 扩展动作
        // 回调动作
        id acf0 = [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)];
        // 回调动作,传递动画自身指针
        id acf1 = [CCCallFuncN actionWithTarget:self selector:@selector(CallBack2:)];  
        // 回调动作,传递动画自身指针已经一个参数
        id acf2 = [CCCallFuncND actionWithTarget:self selector:@selector(CallBack3:data:) data:(void*)2];
        id action26 = [CCSequence actions:action19, action18, acf0, action23, action0, nil];
        // 反转动作,只能用在有方向有顺序的动作上
        id action27 = [action9 reverse];

        // 速度变化
        //id ac = [CCSequence actions:action9,action27,nil];
        id actiontest = [CCMoveBy actionWithDuration:0.5 position:ccp(200,0)];
        id  ac = [CCSequence actions:actiontest,actiontest, nil];
        // 渐快
        id action28 = [CCEaseIn actionWithAction:ac rate:3];
        // 渐慢
        id action29 = [CCEaseOut actionWithAction:ac rate:3];
        // 先渐快再渐慢
        id action30 = [CCEaseInOut actionWithAction:ac rate:3];
        // 正弦波移动
        id action31 = [CCEaseSineIn actionWithAction:ac];
        id action32 = [CCEaseSineOut actionWithAction:ac];
        id action33 = [CCEaseSineInOut actionWithAction:ac];
        // 由极慢至极快
        id action34 = [CCEaseExponentialIn actionWithAction:ac];
        // 由极快到极慢
        id action35 = [CCEaseExponentialOut actionWithAction:ac];
        // 由极慢至极快 再由极快到慢
        id action36 = [CCEaseExponentialInOut actionWithAction:ac];
        // 手动设定速度,可通过SetSpeed不断调整
        id action37 = [CCSpeed actionWithAction:ac speed:(CCRANDOM_0_1() * 5)];

        [sprTest runAction:action37];
    
	}  
}
// 回调函数1
- (void) CallBack1
{
	[sprTest runAction:[CCTintBy actionWithDuration:2 red:255 green:0 blue:255]];	
}

// 回调函数2
- (void) CallBack2:(id)sender
{
    [sender runAction:[CCTintBy actionWithDuration:1 red:255 green:0 blue:255]];
}

// 回调函数3
-(void) CallBack3:(id)sender data:(void*)data
{
	[sender runAction:[CCTintBy actionWithDuration:(NSInteger)data red:255 green:0 blue:255]];	
}
 

你可能感兴趣的:(CCSprite各种动作介绍和使用)