public Animation(string[] files, SpriteObj animationOwner, float fps) { Loop = true; IsPlaying = true; numFrames = files.Length; owner = animationOwner; sprites = new Sprite[numFrames]; for (int i = 0; i < sprites.Length; i++) { sprites[i] = new Sprite(files[i]); } owner.SetSprite(sprites[0]); if (fps > 0.0f) { frameDuration = 1 / fps; } else { frameDuration = 0.0f; } }
public void Update() { if (owner != null && IsPlaying) { if (frameDuration != 0.0f) { counter += Game.DeltaTime; if (counter >= frameDuration) { counter = 0; currentFrame = (currentFrame + 1);// % numFrames; } } else { owner.SetSprite(sprites[currentFrame]); } } }