public SpriteAnimationInstance CreateInstance() { SpriteAnimationInstance instance = new SpriteAnimationInstance(); instance.Init(this); return(instance); }
public void Initialize() { HealthIconAnimation = SpriteAnimationFactory.CreateAnimationInstance(SpriteAnimationType.OwlHealthIcon); MoneyBagIconAnimation = SpriteAnimationFactory.CreateAnimationInstance(SpriteAnimationType.Bonbon_Gold); CrossAnimation = SpriteAnimationFactory.CreateAnimationInstance(SpriteAnimationType.Cross); DigitAnimations = new SpriteAnimationInstance[10]; for (int digit = 0; digit < DigitAnimations.Length; digit++) { SpriteAnimationType animType = SpriteAnimationType.Digit0 + digit; DigitAnimations[digit] = SpriteAnimationFactory.CreateAnimationInstance(animType); } KeyRingAnchor.AttachTo(HealthIconAnchor); KeyRingAnchor.Position.Y += 64; KeyAnimations = new SpriteAnimationInstance[(int)KeyType.COUNT]; for (int keyIndex = 0; keyIndex < KeyAnimations.Length; keyIndex++) { SpriteAnimationType animType = SpriteAnimationType.Key_Gold + keyIndex; KeyAnimations[keyIndex] = SpriteAnimationFactory.CreateAnimationInstance(animType); } }
public override void Initialize() { base.Initialize(); foreach (SpriteAnimationType type in AnimationTypes) { SpriteAnimationInstance animation = SpriteAnimationFactory.CreateAnimationInstance(type); AnimationInstances.Add(type, animation); } ChangeActiveAnimation(AnimationTypes[0]); }
public void Draw(Renderer renderer, float deltaSeconds) { CrossAnimation.Update(deltaSeconds); foreach (SpriteAnimationInstance anim in DigitAnimations) { anim.Update(deltaSeconds); } foreach (SpriteAnimationInstance anim in KeyAnimations) { anim.Update(deltaSeconds); } if (HealthIconAnimation != null) { HealthIconAnimation.Update(deltaSeconds); int hp = Owliver.Health.MaxHealth; SpatialData spatial = HealthIconAnchor.GetWorldSpatialData(); const float spacing = 3; for (int healthIndex = 0; healthIndex < hp; healthIndex++) { Color tint = healthIndex < Owliver.Health.CurrentHealth ? FullHealthTint : NoHealthTint; HealthIconAnimation.Draw(renderer, spatial.GetWorldSpatialData(), tint: tint); spatial.Position.X += HealthIconAnimation.ScaledDim.X + spacing; } } if (Owliver.MoneyBag != null) { MoneyBagIconAnimation.Update(deltaSeconds); SpatialData spatial = MoneyBagIconAnchor.GetWorldSpatialData(); MoneyBagIconAnimation.Draw(renderer, MoneyBagIconAnchor); const float spacing = 3; float previousAnimWidth = MoneyBagIconAnimation.ScaledDim.X; spatial.Position.X -= 0.5f * CrossAnimation.ScaledDim.X + 0.5f * previousAnimWidth + spacing; CrossAnimation.Draw(renderer, spatial); previousAnimWidth = CrossAnimation.ScaledDim.X; int value = Owliver.MoneyBag.CurrentAmount; while (true) { int digit = value % 10; SpriteAnimationInstance digitAnim = DigitAnimations[digit]; spatial.Position.X -= 0.5f * previousAnimWidth + 0.5f * digitAnim.ScaledDim.X + spacing; digitAnim.Draw(renderer, spatial); value /= 10; if (value == 0) { break; } previousAnimWidth = digitAnim.ScaledDim.X; } } if (Owliver.KeyRing != null) { SpatialData anchor = KeyRingAnchor.GetWorldSpatialData(); for (int keyTypeIndex = 0; keyTypeIndex < (int)KeyType.COUNT; keyTypeIndex++) { KeyType keyType = (KeyType)keyTypeIndex; int keyAmount = Owliver.KeyRing[keyType]; SpriteAnimationInstance keyAnim = KeyAnimations[keyTypeIndex]; SpatialData spatial = anchor.GetWorldSpatialData(); for (int keyIndex = 0; keyIndex < keyAmount; keyIndex++) { keyAnim.Draw(renderer, spatial); spatial.Position.X += 0.6f * keyAnim.ScaledDim.X; } anchor.Position.Y += 0.8f * keyAnim.ScaledDim.Y; } } }