Example #1
0
        public void Update(GameTime gameTime)
        {
            if (isAnimating)
            {
                if (animationType == AnimationType.MoveInFromBottom)
                {
                    if (offset.Y > 0)
                    {
                        offset.Y -= (float)(1 / gameTime.ElapsedGameTime.TotalMilliseconds) * animationSpeedFactor;
                        if (offset.Y < 0)
                        {
                            offset.Y      = 0;
                            isAnimating   = false;
                            animationType = AnimationType.None;
                        }
                    }
                }
                else if (animationType == AnimationType.MoveInFromTop)
                {
                    if (offset.Y < 0)
                    {
                        offset.Y += (float)(1 / gameTime.ElapsedGameTime.TotalMilliseconds) * animationSpeedFactor;
                        if (offset.Y > 0)
                        {
                            offset.Y      = 0;
                            isAnimating   = false;
                            animationType = AnimationType.None;
                        }
                    }
                }
                else if (animationType == AnimationType.MoveOutToTop)
                {
                    if (offset.Y > -(size.Y * 2))
                    {
                        offset.Y -= (float)(1 / gameTime.ElapsedGameTime.TotalMilliseconds) * animationSpeedFactor;
                        if (offset.Y < -(size.Y * 2))
                        {
                            offset.Y      = -size.Y * 2;
                            isAnimating   = false;
                            animationType = AnimationType.None;
                        }
                    }
                }
                else if (animationType == AnimationType.MoveOutToBottom)
                {
                    if (offset.Y < gameController._HEIGHT + size.Y)
                    {
                        offset.Y += (float)(1 / gameTime.ElapsedGameTime.TotalMilliseconds) * animationSpeedFactor;
                        if (offset.Y > gameController._HEIGHT + size.Y)
                        {
                            offset.Y      = gameController._HEIGHT + size.Y;
                            isAnimating   = false;
                            animationType = AnimationType.None;
                        }
                    }
                }

                backgroundRectangle.changeRect(new Rectangle((int)(position.X + offset.X), (int)(position.Y + offset.Y), (int)size.X, (int)size.Y));
            }
        }
Example #2
0
 public void setOffset(Rectangle r)
 {
     offset.X = r.X;
     offset.Y = r.Y;
     backgroundRectangle.changeRect(r);
 }