/// <summary> /// Animates the <see cref="FrameworkElement"/> in by specified animation /// </summary> /// <param name="element">The element to animate</param> /// <param name="animation">The type of animation to do</param> /// <param name="time">The time animation will take</param> /// <returns></returns> public static async Task AnimateInAsync(this FrameworkElement element, ElementAnimation animation, float time = 0.7f) { // Make sure we have something to do if (animation == ElementAnimation.None) { return; } // Get application size to know how big animation will be var appSize = (int)Application.Current.MainWindow.Width; // Based on animation type... switch (animation) { // Start desired animation case ElementAnimation.SlideFromLeft: await element.SlideInAsync(AnimationSlideInDirection.Left, false, time, size : appSize); break; case ElementAnimation.SlideAndFadeInFromLeft: await element.SlideAndFadeInAsync(AnimationSlideInDirection.Left, false, time, size : appSize); break; case ElementAnimation.SlideFromRight: await element.SlideInAsync(AnimationSlideInDirection.Right, false, time, size : appSize); break; case ElementAnimation.SlideAndFadeInFromRight: await element.SlideAndFadeInAsync(AnimationSlideInDirection.Right, false, time, size : appSize); break; case ElementAnimation.SlideFromTop: await element.SlideInAsync(AnimationSlideInDirection.Top, false, time, size : appSize); break; case ElementAnimation.SlideAndFadeInFromTop: await element.SlideAndFadeInAsync(AnimationSlideInDirection.Top, false, time, size : appSize); break; case ElementAnimation.SlideFromBottom: await element.SlideInAsync(AnimationSlideInDirection.Bottom, false, time, size : appSize); break; case ElementAnimation.SlideAndFadeInFromBottom: await element.SlideAndFadeInAsync(AnimationSlideInDirection.Bottom, false, time, size : appSize); break; } }
/// <summary> /// Animates the <see cref="FrameworkElement"/> out by specified animation /// </summary> /// <param name="element">The element to animate</param> /// <param name="animation">The type of animation to do</param> /// <param name="time">The time animation will take</param> /// <returns></returns> public static async Task AnimateOutAsync(this FrameworkElement element, ElementAnimation animation, float time = 0.7f) { // Make sure we have something to do if (animation == ElementAnimation.None) { return; } // Based on animation type... switch (animation) { // Start desired animation case ElementAnimation.SlideToLeft: await element.SlideOutAsync(AnimationSlideInDirection.Left, time); break; case ElementAnimation.SlideAndFadeOutToLeft: await element.SlideAndFadeOutAsync(AnimationSlideInDirection.Left, time); break; case ElementAnimation.SlideToRight: await element.SlideOutAsync(AnimationSlideInDirection.Right, time); break; case ElementAnimation.SlideAndFadeOutToRight: await element.SlideAndFadeOutAsync(AnimationSlideInDirection.Right, time); break; case ElementAnimation.SlideToTop: await element.SlideOutAsync(AnimationSlideInDirection.Top, time); break; case ElementAnimation.SlideAndFadeOutToTop: await element.SlideAndFadeOutAsync(AnimationSlideInDirection.Top, time); break; case ElementAnimation.SlideToBottom: await element.SlideOutAsync(AnimationSlideInDirection.Bottom, time); break; case ElementAnimation.SlideAndFadeOutToBottom: await element.SlideAndFadeOutAsync(AnimationSlideInDirection.Bottom, time); break; } }
public ElementAnimation GetAnimation(LayerObject layerObject) { ElementAnimation animation = new ElementAnimation(); Vector2 position = new Vector2(layerObject.DestinationRectangle.X, layerObject.DestinationRectangle.Y); animation.LoadContent(layerObject.AnimationSequence, layerObject.DestinationRectangle, layerObject.Width, layerObject.Height, layerObject.AnimationRandomness.Value); return(animation); }
void FrameTick(object context) { lock (this) { if (Render == null) { return; } Render.Clear(); if (ContentElements != null) { foreach (SignElement e in ContentElements) { e.SetContext(Render); } // Advance anmiation if (DelayTime > 0) { DelayTime--; } else { if (AnimateFirstElement >= ContentElements.Length) { DelayTime = RecycleDelay; AnimateFirstElement = 0; AnimateElementOffset = 0; } else { // Scrolling SignElement firstElement = ContentElements[AnimateFirstElement]; AnimateElementOffset--; int elementLocation = Render.Configuration.Width + AnimateElementOffset; if (elementLocation + firstElement.Width < 0) { // Advance to next element AnimateFirstElement++; AnimateElementOffset += firstElement.Width + ElementSpacing; } DelayTime = FramesPerScroll - 1; } } // Render ElementAnimation animMode = ElementAnimation.None; int offset = 0; for (int i = AnimateFirstElement; i < ContentElements.Length; i++) { SignElement curElement = ContentElements[i]; if (animMode == ElementAnimation.None) { animMode = curElement.Animation; } if (animMode != curElement.Animation) { break; } Render.ElementXOffset = Render.Configuration.Width + AnimateElementOffset + offset; Render.ElementYOffset = 0; if (Render.ElementXOffset >= Render.Configuration.Width) { break; } curElement.Render(Render); offset += curElement.Width + ElementSpacing; } } SendFrameComplete(); if (ContentElements != null) { // Rebuild content list if necessary. Do this after rendering to reduce jitter. // May not be that important. (measure later) bool needRebuild = false; foreach (ISignContent sc in ContentSources) { if (sc.HasUpdate) { needRebuild = true; } } if (needRebuild) { ContentElements = ContentSources.SelectMany((s) => s.GetElements()).ToArray(); } } } }
public void AddElement(LayerObject[] layerObjects, LayerType type) { foreach (LayerObject layerObject in layerObjects) { MapCollision collision = null; MapElement mapElement = null; switch (type) { case LayerType.Background: mapElement = new MapElement(layerObject.Source.Value, layerObject.DestinationRectangle); backgroundElements.Add(mapElement); break; case LayerType.Parallax: ParallaxElement.HorizontalDirection parallaxDirection = ParallaxElement.HorizontalDirection.Left; if (layerObject.Direction == "right") { parallaxDirection = ParallaxElement.HorizontalDirection.Right; } mapElement = new ParallaxElement(layerObject.MoveSpeed.Value, parallaxDirection, layerObject.Source.Value, layerObject.DestinationRectangle); backgroundElements.Add(mapElement); break; case LayerType.PathBlock: collision = new PathBlockCollision(layerObject.DestinationRectangle); collisions.Add(collision); break; case LayerType.SceneryElements: if (layerObject.Collision != null) { collision = new PathBlockCollision(layerObject.Collision.Value); collisions.Add(collision); if (layerObject.AnimationSequence != null) { ElementAnimation animation = GetAnimation(layerObject); mapElement = new MapElement( layerObject.Source.Value, layerObject.DestinationRectangle, animation, collision ); } else { mapElement = new MapElement(layerObject.Source.Value, layerObject.DestinationRectangle, collision); } middlegroundElements.Add(mapElement); } else { if (layerObject.AnimationSequence != null) { ElementAnimation animation = GetAnimation(layerObject); mapElement = new MapElement( layerObject.Source.Value, layerObject.DestinationRectangle, animation); } else { mapElement = new MapElement(layerObject.Source.Value, layerObject.DestinationRectangle); } mapElement = new MapElement(layerObject.Source.Value, layerObject.DestinationRectangle); middlegroundElements.Add(mapElement); } break; case LayerType.Transition: Rectangle rectangle = new Rectangle(layerObject.X, layerObject.Y, layerObject.Width, layerObject.Height); collision = new TransitionCollision(layerObject.ToId.Value, layerObject.ToMap, rectangle); collisions.Add(collision); break; } } }