精灵套件帧速率在开始时仅下降一次

时间:2013-12-14 05:19:36

标签: sprite-kit

我有一个运行和跳跃的精灵(像马里奥),我正在使用状态机来帮助运行动画动作,我正在使用纹理图集,一切正常。

 - (void)jumpingphysics {

if (_JumpBool && self.onGround) {
    _doubleJumpBool = YES;
    _JumpBool = NO;

    [self catJump];
    self.physicsBody.velocity = CGVectorMake(0.0, 600);
}
// double jump
if (_JumpBool && _doubleJumpBool) {
    self.physicsBody.velocity = CGVectorMake(0.0, 600);
    [self catDoubleJump];
    _doubleJumpBool = NO;
    _JumpBool = NO;

}
}

这是所谓的方法。

 - (void)catJump {
if (_actionState == kActionStateIdle || _actionState == kActionStateWalk || _actionState ==         kActionStateJump) {
    [self removeAllActions];
    [self runAction:_jumpAction];
    SKAction *jumpFx = [SKAction playSoundFileNamed:@"jump.wav" waitForCompletion:NO];
    [self runAction:jumpFx];
    _actionState = kActionStateJump;

}
}

这是我创建帧数组动画的地方。

 - (void)catJumpAnimation {
int i;

NSMutableArray *jumpFrames = [NSMutableArray arrayWithCapacity:9];
for (i = 1 ; i < 9; ++i) {
    NSString *frames = [NSString stringWithFormat:@"jump%d.png",i];
    SKTexture *temp = [catAtlas textureNamed:frames];
    [jumpFrames addObject:temp];

    self.jumpAction = [SKAction animateWithTextures:jumpFrames timePerFrame:1.0 / 16.0       resize:YES restore:NO];
}
}

问题是在iPad mini上运行时,当我第一次跳时,我的帧速率下降到40,只是第一次,而且只在我的iPad mini上,而不是我的iPhone 5 c。

我知道它的[自我catJump]调用导致帧速率下降,但我很困惑,为什么只有那个调用导致下降,我有其他动画做更多工作但不会导致下降。

任何想法都将不胜感激。 :d

1 个答案:

答案 0 :(得分:3)

在我的ActionSprite.h类中,它处理控制动画和声音的方法。

 @interface ActionSprite : SKSpriteNode

 @property (nonatomic,strong)SKAction *jumpFx;
 @property (nonatomic,strong)SKAction *DjumpFx;
 @property (nonatomic,strong)SKAction *hurtFx;
 @property (nonatomic,strong)SKAction *dashFx;
 @property (nonatomic,strong)SKAction *defeatFx;
 @property (nonatomic,strong)SKAction *powerFx;
 @property (nonatomic,strong)SKAction *bounceFx;
 @property (nonatomic,strong)SKAction *rocketFx;

在我的ActionSprite.m

  @implementation ActionSprite

- (id)init {
   if (self = [super init]) {


  }
  return self;
  }

- (void)preLoadSound {
_jumpFx = [SKAction playSoundFileNamed:@"jump.wav" waitForCompletion:NO];
_DjumpFx = [SKAction playSoundFileNamed:@"dJump.wav" waitForCompletion:NO];
_hurtFx = [SKAction playSoundFileNamed:@"cat hurt.wav" waitForCompletion:NO];
_defeatFx = [SKAction playSoundFileNamed:@"defeat.wav" waitForCompletion:NO];
_bounceFx = [SKAction playSoundFileNamed:@"bounce.wav" waitForCompletion:NO];
_powerFx = [SKAction playSoundFileNamed:@"power.mp3" waitForCompletion:NO];
_rocketFx = [SKAction playSoundFileNamed:@"rocketFx.wav" waitForCompletion:NO];

}

在cat类中预加载声音

 @implementation Cat

 SKTextureAtlas *catAtlas;

   - (id)init {
   if (self = [super initWithImageNamed:@"idle.png"]) {
    catAtlas = [SKTextureAtlas atlasNamed:@"idle.plist"];

    [self preLoadSound];

}
return self;
}

不再滞后! :d