Пример #1
0
        public TextureTransitionInstances CreateTexture(Texture2D tex, Vector2 origin, int timeBeforeFade, int fadeDuration, float growShrinkFactor, Color color)
        {
            TextureTransitionInstances fader = new TextureTransitionInstances();

            fader.Type               = TextureTransitionInstances.InstanceType.texture;
            fader.Rectangle          = new Rectangle((int)origin.X, (int)origin.Y, tex.Width, tex.Height);
            fader.StartTime          = DateTime.Now;
            fader.TexColor           = color;
            fader.Texture            = tex;
            fader.Position           = origin;
            fader.OriginalPosition   = origin;
            fader.FadeDuration       = fadeDuration;
            fader.DurationBeforeFade = timeBeforeFade;
            fader.GrowShrinkFactor   = growShrinkFactor;
            return(fader);
        }
Пример #2
0
        private void ManageMovements(TextureTransitionInstances textureFade, TimeSpan sinceBeginning)
        {
            List <TransitionMovement> movementsToClear = new List <TransitionMovement>();

            foreach (TransitionMovement movement in textureFade.Movements)
            {
                if (movement.StartTime == 0)
                {
                    //do this immediately.
                    movement.StartTime = (int)sinceBeginning.TotalMilliseconds - 1;
                }

                if (sinceBeginning.TotalMilliseconds > movement.StartTime)
                {
                    if (sinceBeginning.TotalMilliseconds < (movement.StartTime + movement.Duration))
                    {
                        //we should apply this movement.
                        int   totalMillisecondsSoFar   = (int)sinceBeginning.TotalMilliseconds;
                        int   millisecondsIntoMovement = totalMillisecondsSoFar - movement.StartTime;
                        float percentComplete          = (float)millisecondsIntoMovement / (float)movement.Duration;

                        if (textureFade.Type == TextureTransitionInstances.InstanceType.spritefont)
                        {
                            textureFade.Position = textureFade.OriginalPosition + (percentComplete * movement.Movement);
                        }
                        else
                        {
                            Vector2 newRecPos = textureFade.OriginalPosition + (percentComplete * movement.Movement);
                            textureFade.Rectangle = new Rectangle((int)newRecPos.X, (int)newRecPos.Y, textureFade.Rectangle.Width, textureFade.Rectangle.Height);
                        }
                    }
                    else
                    {
                        //we've finished the movement - make sure we're in the desired spot and remove the
                        //movement transition from the list of things to apply.
                        movementsToClear.Add(movement);
                        textureFade.Position         = textureFade.OriginalPosition + movement.Movement;
                        textureFade.OriginalPosition = textureFade.Position;
                    }
                }
            }
            foreach (TransitionMovement movement in movementsToClear)
            {
                textureFade.Movements.Remove(movement);
            }
            movementsToClear.Clear();
        }
Пример #3
0
        public TextureTransitionInstances CreateString(SpriteFont font, string text, Vector2 origin, int timeBeforeFade, int fadeDuration, float growShrinkFactor, Color color)
        {
            TextureTransitionInstances fader = new TextureTransitionInstances();

            fader.Type               = TextureTransitionInstances.InstanceType.spritefont;
            fader.StringToDisplay    = text;
            fader.StartTime          = DateTime.Now;
            fader.TexColor           = color;
            fader.Font               = font;
            fader.Position           = origin;
            fader.OriginalPosition   = origin;
            fader.FadeDuration       = fadeDuration;
            fader.DurationBeforeFade = timeBeforeFade;
            fader.GrowShrinkFactor   = growShrinkFactor;

            return(fader);
        }
Пример #4
0
        public TextureTransitionInstances CreateAndAddTexture(Texture2D tex, Vector2 origin, int timeBeforeFade, int fadeDuration, float growShrinkFactor, Color color)
        {
            TextureTransitionInstances fader = new TextureTransitionInstances();

            fader.Type               = TextureTransitionInstances.InstanceType.texture;
            fader.Rectangle          = new Rectangle((int)origin.X, (int)origin.Y, tex.Width, tex.Height);
            fader.StartTime          = DateTime.Now;
            fader.TexColor           = color;
            fader.Texture            = tex;
            fader.Position           = origin;
            fader.OriginalPosition   = origin;
            fader.FadeDuration       = fadeDuration;
            fader.DurationBeforeFade = timeBeforeFade;
            fader.GrowShrinkFactor   = growShrinkFactor;
            TexturesToFade.Insert(0, fader); //always insert textures at the back of the list, so strings get drawn later
            return(fader);
        }