Example #1
0
        private SCNAction PulseAction()
        {
            var pulseOutAction = SCNAction.FadeOpacityTo(0.4f, 0.5f);
            var pulseInAction  = SCNAction.FadeOpacityTo(1.0f, 0.5f);

            pulseOutAction.TimingMode = SCNActionTimingMode.EaseInEaseOut;
            pulseInAction.TimingMode  = SCNActionTimingMode.EaseInEaseOut;

            return(SCNAction.RepeatActionForever(SCNAction.Sequence(new SCNAction[] { pulseOutAction, pulseInAction })));
        }
Example #2
0
        private void Close(bool flash = false)
        {
            if (!IsOpen || IsAnimating)
            {
                return;
            }

            IsAnimating = true;
            StopPulsing(FocusSquareNode());

            // Close animation
            SCNTransaction.Begin();
            SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            SCNTransaction.AnimationDuration       = AnimationDuration / 2f;
            FocusSquareNode().Opacity = 0.99f;
            SCNTransaction.SetCompletionBlock(() => {
                SCNTransaction.Begin();
                SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                SCNTransaction.AnimationDuration       = AnimationDuration / 4f;

                foreach (var segment in segments)
                {
                    segment.Close();
                }

                SCNTransaction.SetCompletionBlock(() => {
                    IsAnimating = false;
                });
                SCNTransaction.Commit();
            });
            SCNTransaction.Commit();

            // Scale/bounce animation
            FocusSquareNode().AddAnimation(ScaleAnimation("transform.scale.x"), "transform.scale.y");
            FocusSquareNode().AddAnimation(ScaleAnimation("transform.scale.y"), "transform.scale.y");
            FocusSquareNode().AddAnimation(ScaleAnimation("transform.scale.z"), "transform.scale.z");

            // Flash?
            if (flash)
            {
                var waitAction    = SCNAction.Wait(AnimationDuration * 0.75f);
                var fadeInAction  = SCNAction.FadeOpacityTo(0.25f, AnimationDuration * 0.125f);
                var fadeOutAction = SCNAction.FadeOpacityTo(0.0f, AnimationDuration * 0.125f);
                FillPlane.RunAction(SCNAction.Sequence(new SCNAction[] { waitAction, fadeInAction, fadeOutAction }));

                var flashSquareAction = FlashAnimation(AnimationDuration * 0.25f);
                foreach (var segment in Segments)
                {
                    segment.RunAction(SCNAction.Sequence(new[] { waitAction, flashSquareAction }));
                }
            }

            IsOpen = false;
        }
Example #3
0
        private void PerformCloseAnimation(bool flash = false)
        {
            if (this.isBorderOpen && !this.isAnimating)
            {
                this.isBorderOpen = false;
                this.isAnimating  = true;

                this.borderNode.RemoveAction("pulse");
                this.borderNode.Opacity = 1f;

                // Close animation
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration       = GameBoard.AnimationDuration / 2f;
                SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

                this.borderNode.Opacity = 0.99f;
                SCNTransaction.SetCompletionBlock(() =>
                {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration       = GameBoard.AnimationDuration / 2f;
                    SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

                    foreach (var segment in this.borderSegments)
                    {
                        segment.Close();
                    }

                    SCNTransaction.SetCompletionBlock(() =>
                    {
                        this.isAnimating = false;
                    });

                    SCNTransaction.Commit();
                });

                SCNTransaction.Commit();

                if (flash)
                {
                    var waitAction    = SCNAction.Wait(GameBoard.AnimationDuration * 0.75f);
                    var fadeInAction  = SCNAction.FadeOpacityTo(0.6f, GameBoard.AnimationDuration * 0.125f);
                    var fadeOutAction = SCNAction.FadeOpacityTo(0f, GameBoard.AnimationDuration * 0.125f);
                    this.FillPlane.RunAction(SCNAction.Sequence(new SCNAction[] { waitAction, fadeOutAction, fadeInAction }));
                }
            }
        }
Example #4
0
        public void WasTouchedByEnemy()
        {
            var time = DateTime.UtcNow.Ticks;

            if (time > this.lastHitTime + 1d)
            {
                this.lastHitTime = time;
                this.model.RunAction(SCNAction.Sequence(new SCNAction[]
                {
                    SCNAction.PlayAudioSource(this.hitSound, false),
                    SCNAction.RepeatAction(SCNAction.Sequence(new SCNAction[]
                    {
                        SCNAction.FadeOpacityTo(0.01f, 0.1f),
                        SCNAction.FadeOpacityTo(1f, 0.1f)
                    }), 4)
                }));
            }
        }
        void WasHit()
        {
            if (isInvincible)
            {
                return;
            }

            isInvincible = true;
            Character.Hit();

            Character.Node.RunAction(SCNAction.Sequence(new [] {
                SCNAction.PlayAudioSource(hitSound, false),
                SCNAction.RepeatAction(SCNAction.Sequence(new [] {
                    SCNAction.FadeOpacityTo(.01f, 0.1),
                    SCNAction.FadeOpacityTo(1f, 0.1)
                }), 7),
                SCNAction.Run(_ => isInvincible = false)
            }));
        }