2013-05-23 4 views
1

이것은 내 코드입니다 ... 조이스틱 위치로 애니메이션을 실행하는 방법. 조이스틱을 완전히 세우면 애니메이션이 빠르게 표시됩니다. 그렇지 않으면 느린조이스틱 위치로 애니메이션을 실행하는 방법은 무엇입니까?

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"walkcycle.plist"] ; 

spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"walkcycle.png"]; 

[heroWorldLayer addChild:spriteSheet]; 

float frameInt = 33.0f; 

CCArray *jumpFrames = [CCArray arrayWithCapacity:33]; 
for(int i = 1; i <= 33; ++i) { 
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Jump_Anim_V0200%02d.png", i]]; 
    [jumpFrames addObject:frame]; 
} 
CCAnimation *jumpAnim = [CCAnimation animationWithFrames:[jumpFrames getNSArray] delay:1/frameInt]; 
CCFiniteTimeAction *jumpAnimate = [CCAnimate actionWithAnimation:jumpAnim restoreOriginalFrame:YES]; 
_jumpAction = [CCRepeat actionWithAction:jumpAnimate times:1]; 


NSMutableArray *runFrames = [NSMutableArray array]; 
for(int i = 1; i <= 11; ++i) { 
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Run_Anim00%02d.png", i]]; 
    [runFrames addObject:frame]; 
} 

CCAnimation *runAnim = [CCAnimation animationWithFrames:runFrames delay:1.0f/22.0f]; 
CCAnimate *runAnimate = [CCAnimate actionWithAnimation:runAnim restoreOriginalFrame:NO]; 
_runAction = [CCRepeatForever actionWithAction:runAnimate]; 


NSMutableArray *walkFrames = [NSMutableArray array]; 
for(int i = 1; i <= 8; ++i) { 
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"walkcycle00%02d.png", i]]; 
    [walkFrames addObject:frame]; 
} 

CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkFrames delay:(1-(controls.joyStickPos.x))/16.0f]; 
CCAnimate *walkAnimate = [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]; 
_walkAction = [CCRepeatForever actionWithAction:walkAnimate]; 


if (controls.joyStickPos.x < 0) { 
    heroBodySprite.flipX = YES; 

} else { 
    heroBodySprite.flipX = NO; 
} 

if(controls.joyStickPos.x ==0){ // joystick pos 
     if (_actionState != kActionStateWalk || _actionState == kActionStateIdle) { 
      [heroBodySprite stopAllActions]; 
      [heroBodySprite runAction:_runAction]; 
      _actionState = kActionStateWalk; 
     } else { 
      _actionState = kActionStateIdle; 
     } 
} 

// joystick.pos.x == 0 내 애니메이션, 그렇지 않으면 애니메이션을 조이스틱/D-패드 기능이 비열한 입력

if(controls.jmpBtn) { //joystick control jump 
     if (_actionState != kActionStateJump || _actionState == kActionStateIdle) { 
      [heroBodySprite stopAllActions]; 
      [heroBodySprite runAction:_jumpAction]; 
      _actionState = kActionStateJump; 
     } else { 
      _actionState = kActionStateIdle; 
     } 

     [self jump]; 
    } 
when pressing only jump button no animation but if joystick and jump button move and press together then jump animation stop. 

답변

0
int current_state = 0; // at class implementation time 

if ((controls.joyStickPos.x >= 0.7 || controls.joyStickPos.x <= -0.7) && current_state != 1){ 
    current_state = 1; 
    [self runAnimation]; 
} else { 

} 

if (((controls.joyStickPos.x > 0 && controls.joyStickPos.x < 0.7) || (controls.joyStickPos.x < 0 && controls.joyStickPos.x > -0.7)) && current_state != 2){ 
    current_state = 2; 
    [self walkAnimation]; 
} else { 

} 

if (controls.joyStickPos.x == 0 && current_state != 0) { 
    [heroBodySprite stopAllActions]; 
    [wheelSprite stopAllActions]; 
    current_state = 0; 
} else { 

} 
0

체크 아웃 표시하지 : here 이를 당신을 위해 대부분의 일을합니다!

이 정확한 코드가 아닙니다,하지만이

if (joystick.position.x <= joystick.position.x - 20) { 
//Play slow animation 
} 
else { 
//Play fast animation 
} 
+0

어떤 애니메이션에 대해 같은 수 ... 당신은 단지 몇 가지 테스트를 수행하고의 위치를 ​​결정해야 – Gaurav

+0

조이스틱 예를 들어 내 대답을 참조하십시오 – LAMBORGHINI

관련 문제