これは私のコードです...ジョイスティックの位置でアニメーションを実行する方法。ジョイスティックを完全に伸ばすと、アニメーションが速く表示されます。そうでなければ遅い
[[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 での私のアニメーションそれ以外の場合はアニメーションを表示しません
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.