Example #1
0
 public Parallax(Game game, SpriteBatch spriteBatch, ParallaxDirection direction)
     : base(game)
 {
     this.game = game;
     this.spriteBatch = spriteBatch;
     this.direction = direction;
     layers = new List<ParrallaxLayer>();
 }
Example #2
0
 public ParrallaxLayer(Game game, string entity, float speed, float zIndex, ParallaxDirection direction)
 {
     Direction = direction;
     Entity1 = game.Content.Load<Texture2D>(entity);
     Entity2 = game.Content.Load<Texture2D>(entity);
     Speed = speed;
     ZIndex = zIndex;
     Position1 = new Vector2(0);
     Position2 = new Vector2(Entity1.Width * (int)direction, Position1.Y);
 }
Example #3
0
        private void AssociatedObject_MouseMove(object sender, MouseEventArgs e)
        {
            if (!(AssociatedObject.Content is Panel content))
            {
                return;
            }

            var mouse = e.GetPosition(AssociatedObject);

            foreach (FrameworkElement item in content.Children)
            {
                if (!GetUseParallax(item))
                {
                    continue;
                }

                int xoffset = GetXOffset(item);
                int yoffset = GetYOffset(item);
                ParallaxDirection xdirection = GetXDirection(item);
                ParallaxDirection ydirection = GetYDirection(item);

                double newX = AssociatedObject.ActualHeight - (xdirection == ParallaxDirection.From ? (mouse.X / xoffset) : -(mouse.X / xoffset)) - AssociatedObject.ActualHeight;
                double newY = AssociatedObject.ActualWidth - (xdirection == ParallaxDirection.From ? (mouse.Y / yoffset) : -(mouse.Y / yoffset)) - AssociatedObject.ActualWidth;

                if (!(item.RenderTransform is TranslateTransform))
                {
                    item.RenderTransform = new TranslateTransform(newX, newY);
                }
                else
                {
                    TranslateTransform transform = (TranslateTransform)item.RenderTransform;
                    if (xoffset > 0)
                    {
                        transform.X = newX;
                    }
                    if (yoffset > 0)
                    {
                        transform.Y = newY;
                    }
                }
            }
        }
Example #4
0
 public static void SetYDirection(DependencyObject obj, ParallaxDirection value) => obj.SetValue(YDirectionProperty, value);
 public ParallaxBackground(List<Texture2D> scrollingTextures, ParallaxDirection direction)
 {
     _direction = direction;
     ScrollingTextures = scrollingTextures;
     Initialize();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ParallaxBackground"/> class.
 /// </summary>
 /// <param name="ScrollingTextures">The scrolling textures. Order of texture should be maintained.</param>
 /// <param name="Direction">The direction.</param>
 /// <remarks></remarks>
 public ParallaxBackground(List<Texture2D> ScrollingTextures, ParallaxDirection Direction)
 {
     this._direction = Direction;
     this.ScrollingTextures = ScrollingTextures;
     Initialize();
 }
        } // Position
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="ParallaxBackground"/> class.
        /// </summary>
        /// <param name="ScrollingTextures">The scrolling textures. Order of texture should be maintained.</param>
        /// <param name="Direction">The direction.</param>
        /// <remarks></remarks>
        public ParallaxBackground(List <Texture2D> ScrollingTextures, ParallaxDirection Direction)
        {
            this._direction        = Direction;
            this.ScrollingTextures = ScrollingTextures;
            Initialize();
        }