// Vaihtaa transitionin ja päivittää isFinishedin statea.
        private void ChangeTransition()
        {
            if (!isFinished)
            {
                // Otetaan tässä lohkossa eka mahdollinen transitioni.
                // Ottaa outTransitionin jossei se ole null ja vise versa.
                if (currentTransition == null)
                {
                    if (outTransition != null)
                    {
                        currentTransition = outTransition;
                    }
                    else
                    {
                        // Ammutaan out transitionin finished event suoraan.
                        LaunchOutFinished();

                        currentTransition = inTransition;
                    }
                }
                else
                {
                    if (currentTransition == outTransition)
                    {
                        LaunchOutFinished();

                        if (inTransition != null)
                        {
                            currentTransition = inTransition;
                        }
                        else
                        {
                            LaunchInFinished();
                        }
                    }
                    else
                    {
                        LaunchInFinished();
                        currentTransition = null;
                    }
                }

                // Alotetaan uusi transitoni jossei olla toistettu molempia.
                if (currentTransition != null && !currentTransition.IsStarted)
                {
                    currentTransition.Start();
                }
                else
                {
                    isFinished = true;

                    if (OnFinished != null)
                    {
                        OnFinished(this, new GameEventArgs());
                    }
                }
            }
        }
        /// <summary>
        /// Called when starting the scene
        /// </summary>
        public override void OnStart()
        {
            // Create render pass
            TriangleRenderPass = new BasicRenderPass(Graphics);
            // Create and start a clear effect
            ClearEffect = new ClearEffect(Graphics, TriangleRenderPass);
            ClearEffect.Start();
            ClearEffect.ClearColor = new ClearColorValue(0.5f, 0.7f, 0.9f);
            // Create and start triangle effect
            SpriteEffect = new SpriteEffect(
                Graphics,
                TriangleRenderPass,
                2000,
                ClearEffect.FinalLayout,
                ClearEffect.FinalAccess,
                ClearEffect.FinalStage
                );
            SpriteEffect.Start();
            var rand  = new Random();
            var tex   = Content["TriangleTexture"] as Texture2D;
            var anims = new[] {
                new Animation(new[] {
                    Animation.Instruction.SetRotation(0f, 0f),
                    Animation.Instruction.SetScale(0f, new Vector2(12f, 12f)),
                    Animation.Instruction.LerpScale(0f, 1f, new Vector2(30f, 10f)),
                    Animation.Instruction.SetRectangle(0f, new Vector2(0f, 0f), new Vector2(1f, 1f)),
                    Animation.Instruction.LerpScale(1f, 1f, new Vector2(8f, 20f)),
                    Animation.Instruction.LerpRotation(1f, 1f, 1f),
                    Animation.Instruction.SetRectangle(1f, new Vector2(0.6f, 0.6f), new Vector2(1f, 1f)),
                    Animation.Instruction.LerpScale(2f, 1f, new Vector2(12f, 12f)),
                    Animation.Instruction.LerpRotation(2f, 1f, 0f),
                    Animation.Instruction.None(3f)
                }),
                new Animation(new[] {
                    Animation.Instruction.SetScale(0f, new Vector2(26f, 26f)),
                    Animation.Instruction.LerpScale(0f, 1f, new Vector2(8f, 30f)),
                    Animation.Instruction.SetRectangle(0f, new Vector2(0f, 0f), new Vector2(1f, 1f)),
                    Animation.Instruction.LerpScale(0.7f, 1f, new Vector2(20f, 8f)),
                    Animation.Instruction.SetRectangle(0.7f, new Vector2(0f, 0f), new Vector2(0.5f, 0.5f)),
                    Animation.Instruction.LerpScale(1.4f, 1f, new Vector2(26f, 26f)),
                    Animation.Instruction.None(2.141f)
                }),
                new Animation(new[] {
                    Animation.Instruction.SetScale(0f, new Vector2(26f, 26f)),
                    Animation.Instruction.LerpScale(0f, 1f, new Vector2(8f, 30f)),
                    Animation.Instruction.SetRectangle(0f, new Vector2(0f, 0f), new Vector2(1f, 1f)),
                    Animation.Instruction.LerpScale(1.861f, 1f, new Vector2(20f, 8f)),
                    Animation.Instruction.SetRectangle(1.861f, new Vector2(0f, 0f), new Vector2(0.5f, 0.5f)),
                    Animation.Instruction.LerpScale(3f, 1f, new Vector2(26f, 26f)),
                    Animation.Instruction.None(5.12f)
                })
            };

            for (var i = 0; i < 2000; i++)
            {
                var vel = new Vector3(
                    -75f + (float)rand.NextDouble() * 150f,
                    -75f + (float)rand.NextDouble() * 150f,
                    0f
                    );
                var pos = new Vector3(
                    -100f + (float)rand.NextDouble() * 200f,
                    -100f + (float)rand.NextDouble() * 200f,
                    -1f + (float)rand.NextDouble() * 2f
                    );
                new SpriteInstance(
                    SpriteEffect,
                    pos,
                    vel,
                    new Vector2(32, 32),
                    tex,
                    new Vector4(0, 0, 32f / tex.Image.Extent.Width, 32f / tex.Image.Extent.Height),
                    anims[i % 3]
                    );
            }
            TransitionEffect = new TransitionEffect(
                Graphics,
                SpriteEffect.FinalLayout,
                SpriteEffect.FinalAccess,
                SpriteEffect.FinalStage,
                ImageLayout.ColorAttachmentOptimal,
                Accesses.MemoryRead,
                PipelineStages.BottomOfPipe
                );
            TransitionEffect.Start();
        }
Exemple #3
0
        public virtual void Update(GameTime time)
        {
            // jos nykyisellä ruudulla on lopetus siirtymä
            if (leaveTransition != null)
            {
                if (!leaveTransition.IsStarted)
                {
                    leaveTransition.Start();
                }
                leaveTransition.Update(time);
                // jos siirtymä on valmis niin vaihdetaan ruutu seuraavaan
                // ja aletaan suorittamaan aloitus siirtymää
                if (leaveTransition.IsFinished)
                {
                    leaveTransition = null;
                    // jos on viiminen ruutu, niin nextiä ei sillon ole
                    if (next != null)
                    {
                        if (next.IsPopUp)
                        {
                            current.State = ScreenState.Background;
                        }
                        else
                        {
                            current.State = ScreenState.Hidden; // ei ole enää näkyvissä
                        }
                        // vaihdetaan ruutujen paikat
                        T prev = current;
                        current = next;
                        // tyhjennetään nykyisen ruudun viite
                        next          = default(T);
                        current.State = ScreenState.TransitionOn; // ollaan häivyttämässä kuvaa sisään
                        if (prev.IsPopUp)
                        {
                            enterTransition = new EmptyTransition();
                        }
                        else
                        {
                            enterTransition = current.EnterTransition;
                        }

                        if (enterTransition == null)
                        {
                            enterTransition = new EmptyTransition();
                        }
                        enterTransition.Init(current, prev);
                    }
                }
            }
            for (int i = states.Count - 1; i >= 0; i--)
            {
                T state = states[i];
                state.Update(time);
            }
            if (enterTransition != null)
            {
                if (!enterTransition.IsStarted)
                {
                    enterTransition.Start();
                }
                enterTransition.Update(time);
                if (enterTransition.IsFinished)
                {
                    enterTransition  = null;
                    current.State    = ScreenState.Active; // nyt ollaan näkyvissä
                    current.HasFocus = true;


                    for (int i = states.Count - 1; i >= 0; i--)
                    {
                        T state = states[i];
                        if (state.IsExiting)
                        {
                            Remove(state);
                        }
                    }
                }
            }
        }