/// <summary> /// Set the value of the specified AnimationTag. /// </summary> /// <param name="tag">The target AnimationTag to be set.</param> /// <param name="value">The value the specified tag should be set to.</param> public void SetTagValue(AnimationTag tag, bool value) { //If the engine is shutdown ignore any incoming calls. if (_destroyed) { return; } if (_dirty) { Initialize(false); } if (tag == null) { throw new ArgumentNullException(nameof(tag)); } var id = tag.Id; if (id < 0) { Log.Error <CharacterAnimator>("Tried to set the value for an invalid AnimationTag on Entity {0}!", Entity.Name); return; } if (CapFramerate) { _tagValues[id] = value; } else { _animationContext.SetTagValue(tag, value); } }
public PlayerAnimations(Player player, CharacterAnimator animator) { _player = player; _animator = animator; _walkTag = animator.FindTag(WalkTagName); }
public bool IsInCurrentAnimationState(AnimationTag _tag) { if (anim.GetCurrentAnimatorStateInfo(0).IsTag(_tag.ToString())) { return(true); } return(false); }
private static void LoadAnimation(string name, string fullPath) { var file = new AsepriteFile(fullPath); var animation = new AnimationData(); for (var i = 0; i < file.Layers.Count; i++) { var layer = file.Layers[i]; var list = new List <AnimationFrame>(); for (var j = 0; j < file.Frames.Count; j++) { var frame = file.Frames[j]; var newFrame = new AnimationFrame(); newFrame.Duration = frame.Duration; newFrame.Texture = new TextureRegion(file.Texture, new Rectangle(j * file.Width, i * file.Height, file.Width, file.Height)); newFrame.Bounds = newFrame.Texture.Source; list.Add(newFrame); } animation.Layers[layer.Name] = list; } for (var i = 0; i < file.Slices.Count; i++) { var slice = file.Slices[i]; animation.Slices[slice.Name] = new TextureRegion(file.Texture, new Rectangle(slice.OriginX, slice.OriginY, slice.Width, slice.Height)); } foreach (var tag in file.Animations.Values) { var newTag = new AnimationTag(); newTag.Direction = (AnimationDirection)tag.Directions; newTag.StartFrame = (uint)tag.FirstFrame; newTag.EndFrame = (uint)tag.LastFrame; animation.Tags[tag.Name] = newTag; } foreach (var tag in file.Tags) { var newTag = new AnimationTag(); newTag.Direction = (AnimationDirection)tag.LoopDirection; newTag.StartFrame = (uint)tag.From; newTag.EndFrame = (uint)tag.To; animation.Tags[tag.Name] = newTag; } animation.Texture = file.Texture; animations[name] = animation; }
private static List <UIElement> GetAllAnimatableChildren(UIElement element) { List <UIElement> children = new List <UIElement>(); if (null != element) { // if the element is animatable, add it if (AnimationTypes.None != AnimationTag.GetAnimationType(element)) { children.Add(element); } // what type is the element? if (element is Panel panelElement) { // element is a panel which has .Children // loop through its children foreach (UIElement child in panelElement.Children) { // yes, recursively get its children children.AddRange(GetAllAnimatableChildren(child)); } } else if (element is Border borderElement) { // element is a border which may have 1 child // is the border animatable? if (AnimationTypes.None != AnimationTag.GetAnimationType(borderElement)) { // yes, add it children.Add(borderElement); } // does the border have a child? if (null != borderElement.Child) { // yes, recursively get its children children.AddRange(GetAllAnimatableChildren(borderElement.Child)); } } //else //{ // // is the element animatable? // if (AnimationTypes.None != AnimationTag.GetAnimationType(element)) // { // // yes, add it // children.Add(element); // } //} } return(children); }
public override void Write(FileWriter writer) { writer.SetByteOrder(true); writer.WriteSignature(Magic); if (!IsBigEndian) { writer.Write((ushort)0xFFFE); } else { writer.Write((ushort)0xFEFF); } writer.SetByteOrder(IsBigEndian); writer.Write(HeaderSize); writer.Write(Version); writer.Write(uint.MaxValue); //Reserve space for file size later writer.Write(ushort.MaxValue); //Reserve space for section count later writer.Seek(2); //padding int sectionCount = 0; WriteSection(writer, "pat1", AnimationTag, () => AnimationTag.Write(writer, this)); sectionCount++; WriteSection(writer, "pai1", AnimationInfo, () => AnimationInfo.Write(writer, this)); sectionCount++; foreach (var section in UnknownSections) { WriteSection(writer, section.Signature, section, () => section.Write(writer, this)); sectionCount++; } //Write the total section count using (writer.TemporarySeek(0x10, System.IO.SeekOrigin.Begin)) { writer.Write((ushort)sectionCount); } //Write the total file size using (writer.TemporarySeek(0x0C, System.IO.SeekOrigin.Begin)) { writer.Write((uint)writer.BaseStream.Length); } }
private void ShowPaymentView(AnimationTag tag) { if (_animations.PaymentIsActive) { return; } if (tag == AnimationTag.Bills) { var hideElements = new FrameworkElement[] { monthDisplay, heading_FoodBills, food_add, heading_creditCards, credit_add, heading_expectedBills, expected_add, foodBills, creditCard, expectedBills }; _animations.StartAnimation(AnimationTag.Payment, paymentPanel, hideElements); } if (tag == AnimationTag.FoodBills) { var hiddenElements = new FrameworkElement[] { monthDisplay, heading_Bills, bills_add, heading_creditCards, credit_add, heading_expectedBills, expected_add, bills_list, creditCard, expectedBills, }; _animations.StartAnimation(AnimationTag.RightToTopLeft, foodBills, hiddenElements); _animations.StartAnimation(AnimationTag.RightToTopLeft, heading_FoodBills); _animations.StartAnimation(AnimationTag.RightToTopLeft, food_add); _animations.StartAnimation(AnimationTag.Payment, paymentPanel); } if (tag == AnimationTag.CreditCardBills) { var hideElements = new FrameworkElement[] { monthDisplay, heading_Bills, bills_add, heading_FoodBills, food_add, heading_expectedBills, expected_add, bills_list, foodBills, expectedBills, }; _animations.StartAnimation(AnimationTag.RightToLeft, creditCard, hideElements); _animations.StartAnimation(AnimationTag.RightToLeft, heading_creditCards); _animations.StartAnimation(AnimationTag.RightToLeft, credit_add); _animations.StartAnimation(AnimationTag.Payment, paymentPanel); } if (tag == AnimationTag.ExpectedUnexpectedBills) { var hideElements = new FrameworkElement[] { monthDisplay, heading_Bills, bills_add, heading_FoodBills, food_add, heading_creditCards, credit_add, bills_list, foodBills, creditCard, }; _animations.StartAnimation(AnimationTag.MiddleToLeft, expectedBills, hideElements); _animations.StartAnimation(AnimationTag.MiddleToLeft, heading_expectedBills); _animations.StartAnimation(AnimationTag.MiddleToLeft, expected_add); _animations.StartAnimation(AnimationTag.Payment, paymentPanel); } }
public void StartAnimation(AnimationTag tag, FrameworkElement element, FrameworkElement[] hiddenElements = null) { if (hiddenElements != null) { foreach (var hiddenElement in hiddenElements) { StartAnimation(AnimationTag.Hide, hiddenElement); } } switch (tag) { case AnimationTag.Next: { _nextAnimations.Start.Begin(element); return; } case AnimationTag.Previous: { _nextAnimations.Revert.Begin(element); return; } case AnimationTag.MiddleToLeft: { _middleToLeft.Start.Begin(element); DisplayedAnimations.Add(new AnimationElement(AnimationTag.MiddleToLeftRevert, element)); return; } case AnimationTag.MiddleToLeftRevert: { _middleToLeft.Revert.Begin(element); return; } case AnimationTag.RightToLeft: { _rightToLeft.Start.Begin(element); DisplayedAnimations.Add(new AnimationElement(AnimationTag.RightToLeftRevert, element)); return; } case AnimationTag.RightToLeftRevert: { _rightToLeft.Revert.Begin(element); return; } case AnimationTag.RightToTopLeft: { _rightBottomToTopLeft.Start.Begin(element); DisplayedAnimations.Add(new AnimationElement(AnimationTag.RightToTopLeftRevert, element)); return; } case AnimationTag.RightToTopLeftRevert: { _rightBottomToTopLeft.Revert.Begin(element); return; } case AnimationTag.Payment: { _paymentView.Start.Begin(element); DisplayedAnimations.Add(new AnimationElement(AnimationTag.PaymentRevert, element)); PaymentIsActive = true; return; } case AnimationTag.PaymentRevert: { _paymentView.Revert.Begin(element); PaymentIsActive = false; return; } case AnimationTag.Hide: { _hide.Start.Begin(element); DisplayedAnimations.Add(new AnimationElement(AnimationTag.HideRevert, element)); return; } case AnimationTag.HideRevert: { _hide.Revert.Begin(element); return; } default: { return; } } }
public AnimationElement(AnimationTag tag, FrameworkElement frameworkElement) { Tag = tag; FrameworkElement = frameworkElement; }
public static void PerformPageEntranceAnimation(Page page) { if (null != page) { // stagger delay counter double staggerDelay = 0; // create default easing CubicEase easeIn = new CubicEase() { EasingMode = EasingMode.EaseIn }; CubicEase easeOut = new CubicEase() { EasingMode = EasingMode.EaseOut }; // storyboards List <Storyboard> storyboards = new List <Storyboard>(); // get all the objects to animate List <UIElement> animatables = GetAllAnimatableChildren(page.Content); // loop through them foreach (UIElement animatable in animatables) { // get the animation tag properties AnimationTypes animationType = AnimationTag.GetAnimationType(animatable); TranslateAxes translateAxis = AnimationTag.GetTranslateAxis(animatable); TranslateDirections translateDirection = AnimationTag.GetTranslateDirection(animatable); // create the animations switch (animationType) { case AnimationTypes.Background: storyboards.Add(CreateEasingAnimation(animatable, "Opacity", 0.0, 0.0, 1.0, DEFAULT_DURATION, staggerDelay, false, false, new RepeatBehavior(1d))); break; case AnimationTypes.Standard: storyboards.Add(CreateEasingAnimation(animatable, "Opacity", 0.0, 0.0, 1.0, DEFAULT_DURATION, staggerDelay, false, false, new RepeatBehavior(1d))); double startValue1 = ((TranslateDirections.FromTop == translateDirection) || (TranslateDirections.FromLeft == translateDirection)) ? -1 * DEFAULT_TRANSLATE_OFFSET : DEFAULT_TRANSLATE_OFFSET; storyboards.Add(CreateTranslateAnimation(animatable, translateAxis, startValue1, startValue1, 0, easeIn, easeOut, DEFAULT_DURATION, staggerDelay, false, false, new RepeatBehavior(1d))); break; case AnimationTypes.Hero: storyboards.Add(CreateEasingAnimation(animatable, "Opacity", 0.0, 0.0, 1.0, DEFAULT_DURATION, staggerDelay, false, false, new RepeatBehavior(1d))); double startValue2 = ((TranslateDirections.FromTop == translateDirection) || (TranslateDirections.FromLeft == translateDirection)) ? -1 * DEFAULT_TRANSLATE_HERO_OFFSET : DEFAULT_TRANSLATE_HERO_OFFSET; storyboards.Add(CreateTranslateAnimation(animatable, translateAxis, startValue2, startValue2, 0, easeIn, easeOut, DEFAULT_DURATION, staggerDelay, false, false, new RepeatBehavior(1d))); break; case AnimationTypes.Radiate: storyboards.Add(CreateEasingAnimation(animatable, "Opacity", 0.0, 0.0, 1.0, DEFAULT_DURATION * 2, staggerDelay, false, false, new RepeatBehavior(1d))); staggerDelay += DEFAULT_DURATION * 2; //storyboards.Add(CreateEasingAnimation(animatable, "Opacity", 0.5, 0.5, 1.0, // DEFAULT_DURATION * 2, staggerDelay, // false, false, new RepeatBehavior(1d))); //staggerDelay += DEFAULT_DURATION; break; case AnimationTypes.None: default: break; } // increment stagger delay staggerDelay += 2 * (DEFAULT_DURATION / 3); } // loop through the animations and start them foreach (Storyboard storyboard in storyboards) { storyboard.Begin(); } } }