public void AnimationDidStop(CAAnimation anim,bool finished)
 {
     if (isAnimating)
     {
         PerformSelector (new Selector("StartAnimatingTransaction"), null, 1.0);
     }
 }
Ejemplo n.º 2
0
 private static CAAnimation ShimmerSlideRepeat(CAAnimation a, double duration, ShimmeringDirection direction)
 {
     CAAnimation anim = (CAAnimation)a.Copy();
     anim.RepeatCount = float.MaxValue;
     anim.Duration = duration;
     anim.Speed = (direction == ShimmeringDirection.Right || direction == ShimmeringDirection.Down)
         ? Math.Abs(anim.Speed)
         : -Math.Abs(anim.Speed);
     return anim;
 }
		public override void AnimationStopped(CAAnimation anim, bool finished)
		{
			completedAnimations += 1;

			if (completedAnimations == this.views.Count)
			{
				this.completedAnimations = 0;

				if (this.AnimationCompleted != null)
				{
					this.AnimationCompleted(this, EventArgs.Empty);
				}
			}
		}
Ejemplo n.º 4
0
        void AttachFadeoutAnimation(CALayer progress, CAAnimation animation, Func <bool> fadeoutVerifier)
        {
            animation.AnimationStopped += (sender, e) => {
                if (!fadeoutVerifier())
                {
                    return;
                }

                CABasicAnimation fadeout = CABasicAnimation.FromKeyPath("opacity");
                fadeout.From                = NSNumber.FromDouble(1);
                fadeout.To                  = NSNumber.FromDouble(0);
                fadeout.Duration            = 0.5;
                fadeout.FillMode            = CAFillMode.Forwards;
                fadeout.RemovedOnCompletion = false;
                fadeout.AnimationStopped   += (sender2, e2) => {
                    if (!e2.Finished)
                    {
                        return;
                    }

                    inProgress       = false;
                    progress.Opacity = 0;
                    progress.RemoveAllAnimations();
                    progress.RemoveFromSuperLayer();
                };
                progress.Name = ProgressLayerFadingId;
                progress.AddAnimation(fadeout, "opacity");
            };
            progress.AddAnimation(animation, growthAnimationKey);
            var oldLayer = ProgressLayer;

            if (oldLayer == null)
            {
                Layer.AddSublayer(progress);
            }

            UpdateLayer();
        }
        private void playAnimationForWhiteCircle()
        {
            var animation = CABasicAnimation.FromKeyPath(path: "path");

            animation.Duration       = 1.55;
            animation.BeginTime      = CAAnimation.CurrentMediaTime() + 0.8;
            animation.To             = FromObject(expandedBlurWhiteCirclePath().CGPath);
            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            animation.RepeatCount    = float.MaxValue;
            // if you remove it the shape will return to the original shape after the animation finished
            animation.FillMode            = CAShapeLayer.FillRuleEvenOdd;
            animation.RemovedOnCompletion = false;
            _blurWhiteCircleLayer.AddAnimation(animation, null);

            var opacityAnimation = CABasicAnimation.FromKeyPath(path: "opacity");

            opacityAnimation.From        = FromObject(0.5f);
            opacityAnimation.To          = FromObject(0f);
            opacityAnimation.BeginTime   = CAAnimation.CurrentMediaTime() + 0.8;
            opacityAnimation.RepeatCount = float.MaxValue;
            opacityAnimation.Duration    = 1.55;
            _blurWhiteCircleLayer.AddAnimation(opacityAnimation, null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Renders the activity spinner and starts the animation.
        /// </summary>
        public void RenderToViewWithAnimation()
        {
            CAShapeLayer circleLayer = new CAShapeLayer();

            nfloat circleSize = (float)Math.Min(this.View.Bounds.Width, this.View.Bounds.Height);

            circleLayer.Path        = this.CreateCirclePath(circleSize, this.lineWidth);
            circleLayer.Position    = new CGPoint(this.View.Bounds.GetMidX(), this.View.Bounds.GetMidY());
            circleLayer.StrokeColor = this.spinnerColor.CGColor;
            circleLayer.FillColor   = UIColor.Clear.CGColor;
            circleLayer.LineWidth   = this.lineWidth;
            circleLayer.LineCap     = CAShapeLayer.CapRound;

            CAAnimation strokeEndAnimation   = this.CreateStrokeAnimation("strokeEnd", Constants.StrokeEndAnimationBeginTime);
            CAAnimation strokeStartAnimation = this.CreateStrokeAnimation("strokeStart", Constants.StrokeStartAnimationBeginTime);
            CAAnimation rotationAnimation    = this.CreateRotationAnimation();

            circleLayer.AddAnimation(strokeEndAnimation, null);
            circleLayer.AddAnimation(strokeStartAnimation, null);
            circleLayer.AddAnimation(rotationAnimation, null);

            this.View.Layer.AddSublayer(circleLayer);
        }
Ejemplo n.º 7
0
        void animate(nfloat pinnedProgress, nfloat currentProgress, double initialDelay, double duration)
        {
            var animation = CABasicAnimation.FromKeyPath(CircularProgressAnimationKeys.progress);

            animation.Duration = duration;

            animation.TimingFunction = TimingFunction;

            animation.From = NSNumber.FromDouble(currentProgress);

            animation.FillMode = CAFillMode.Forwards;

            //animation.RemovedOnCompletion = false;
            animation.RemovedOnCompletion = true;

            animation.To = NSNumber.FromDouble(pinnedProgress);

            animation.BeginTime = CAAnimation.CurrentMediaTime() + initialDelay;

            animation.AnimationStopped += handleAnimationStopped;

            progressLayer.AddAnimation(animation, CircularProgressAnimationKeys.progress);
        }
Ejemplo n.º 8
0
        public void SetupGL()
        {
            Context             = new EAGLContext(EAGLRenderingAPI.OpenGLES2);
            DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24;

            effect = new GLKBaseEffect();
            effect.Light0.Enabled = true;

            EAGLContext.SetCurrentContext(Context);

            GL.Enable(EnableCap.DepthTest);

            GL.Oes.GenVertexArrays(1, out vertexArray);
            GL.Oes.BindVertexArray(vertexArray);

            GL.GenBuffers(1, out vertexBuffer);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(gCubeVertexData.Length * sizeof(float)), gCubeVertexData, BufferUsage.StaticDraw);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.Position);
            GL.VertexAttribPointer((int)GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float, false, 24, 0);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.Normal);
            GL.VertexAttribPointer((int)GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float, false, 24, 12);

            GL.Oes.BindVertexArray(0);

            RandomizeBigCube();

            for (int i = 0; i < NumLittleCubes; i++)
            {
                littleCube[i] = bigCube;
            }

            timeOfLastRenderedFrame = CAAnimation.CurrentMediaTime();
        }
Ejemplo n.º 9
0
        protected virtual void InitMovement(IViewPort viewPort, CGPoint positionToMove)
        {
            link = CADisplayLink.Create(OnDisplayLinkLoop);

            var positionToMoveOffset = positionToMove.Subtract(new CGPoint(viewPort.ViewPortSize.Width / 2, viewPort.ViewSize.Height / 2));

            var moveDelta = positionToMoveOffset.Subtract(viewPort.ViewPortContentOffset);

            decelerationVelocityX = 2D * moveDelta.X / MovementTime;

            decelerationVelocityY = 2D * moveDelta.Y / MovementTime;

            decelerationX = 2D * moveDelta.X / Math.Pow(MovementTime, 2);

            decelerationY = 2D * moveDelta.Y / Math.Pow(MovementTime, 2);

            lastDecelerationFramePositionX = 0;

            lastDecelerationFramePositionY = 0;

            decelerationStartTime = CAAnimation.CurrentMediaTime();

            link.AddToRunLoop(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode);
        }
Ejemplo n.º 10
0
        private void Animate(CALayer layer, float from, float to, float delayMilliseconds, float durationMilliseconds)
        {
            if (_isDiscrete)
            {
                var animation = CAKeyFrameAnimation.FromKeyPath(_property);
                animation.KeyTimes        = new NSNumber[] { new NSNumber(0.0), new NSNumber(1.0) };
                animation.Values          = new NSObject[] { _nsValueConversion(to) };
                animation.CalculationMode = CAKeyFrameAnimation.AnimationDescrete;
                _animation = animation;
            }
            else
            {
                var animation = CABasicAnimation.FromKeyPath(_property);
                animation.From           = _nsValueConversion(from);
                animation.To             = _nsValueConversion(to);
                animation.TimingFunction = _timingFunction;
                _animation = animation;
            }
            _animation.BeginTime           = CAAnimation.CurrentMediaTime() + delayMilliseconds / __millisecondsPerSecond;
            _animation.Duration            = durationMilliseconds / __millisecondsPerSecond;
            _animation.FillMode            = CAFillMode.Forwards;
            _animation.RemovedOnCompletion = false;

            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().DebugFormat("CoreAnimation on property {0} from {1} to {2} is starting.", _property, from, to);
            }

            _onAnimationStarted = (s, e) =>
            {
                var anim = s as CAAnimation;

                if (anim == null)
                {
                    return;
                }

                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().DebugFormat("CoreAnimation on property {0} from {1} to {2} started.", _property, from, to);
                }

                anim.AnimationStarted -= _onAnimationStarted;
                anim.AnimationStopped += _onAnimationStopped;
            };

            _onAnimationStopped = (s, e) =>
            {
                var anim = s as CAAnimation;

                if (anim == null)
                {
                    return;
                }

                CATransaction.Begin();
                CATransaction.DisableActions = true;
                layer.SetValueForKeyPath(_nsValueConversion(to), new NSString(_property));
                CATransaction.Commit();

                anim.AnimationStopped -= _onAnimationStopped;

                if (e.Finished)
                {
                    if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                    {
                        this.Log().DebugFormat("CoreAnimation on property {0} from {1} to {2} finished.", _property, from, to);
                    }

                    _onFinish();

                    ExecuteIfLayer(l => l.RemoveAnimation(_key));
                }
                else
                {
                    if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                    {
                        this.Log().DebugFormat("CoreAnimation on property {0} from {1} to {2} stopped before finishing.", _property, from, to);
                    }

                    anim.AnimationStarted += _onAnimationStarted;
                }
            };

            _animation.AnimationStarted += _onAnimationStarted;

            layer.AddAnimation(_animation, _key);
        }
 public override void AnimationStopped(CAAnimation anim, bool finished)
 {
     ctrl.transitioning = false;
 }
Ejemplo n.º 12
0
 static public void AddAnimation(this ISCNAnimatable self, SCNAnimation animation, string key)
 {
     using (var ca = CAAnimation.FromSCNAnimation(animation))
         using (var st = key != null ? new NSString(key) : null)
             self.AddAnimation(ca, st);
 }
Ejemplo n.º 13
0
 public static void Animate(this UIView view, CAAnimation animation)
 {
     view.Layer.Animate(animation);
 }
Ejemplo n.º 14
0
        void initButtons()
        {
            var moveBtn = UIButton.FromType(UIButtonType.RoundedRect);

            moveBtn.Frame = new RectangleF(View.Bounds.Width - 240, 60, 200, 40);
            moveBtn.SetTitle("Move X", UIControlState.Normal);
            moveBtn.TouchUpInside += (object sender, EventArgs e) => {
                if (logoView.Layer.PresentationLayer.Position.X < 400)
                {
                    Rouse.To(logoView, 1, new RouseLib.KeyPaths {
                        PositionX = 400
                    }, Easing.EaseInExpo);

//					Rouse.To (logoLayer, 1, new RouseLib.KeyPaths{ PositionX = 400}, Easing.EaseInExpo);
                    var localTime = CAAnimation.CurrentMediaTime();

                    var ka = new CAKeyFrameAnimation();
                    ka.KeyPath        = "position.x";
                    ka.BeginTime      = 0;
                    ka.Duration       = 1;
                    ka.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                    ka.Values         = KeyFrameUtils.CreateKeyValues(logoLayer.Position.X, 400f, RouseLib.Easing.EaseInExpo);

//					var ka2 = new CAKeyFrameAnimation ();
//					ka2.KeyPath = "opacity";
//					ka2.BeginTime = 0;
//					ka2.Duration = 1;
//					ka2.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.Linear);
//					ka2.Values = KeyFrameUtils.CreateKeyValues (1, 0.2f, RouseLib.Easing.EaseInExpo);
//
                    var group = CAAnimationGroup.CreateAnimation();
                    group.BeginTime           = localTime;
                    group.Duration            = 1;
                    group.FillMode            = CAFillMode.Forwards;
                    group.RemovedOnCompletion = false;
                    group.Animations          = new CAAnimation[] { ka };
                    logoLayer.AddAnimation(group, null);
                }
                else
                {
                    Rouse.To(logoView, 1, new RouseLib.KeyPaths {
                        PositionX = 70
                    }, Easing.EaseOutExpo);

//					Rouse.To (logoLayer, 1, new RouseLib.KeyPaths{ PositionX = 70}, Easing.EaseOutExpo);
                    var localTime = CAAnimation.CurrentMediaTime();

                    var ka = new CAKeyFrameAnimation();
                    ka.KeyPath        = "position.x";
                    ka.BeginTime      = 0;
                    ka.Duration       = 1;
                    ka.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                    ka.Values         = KeyFrameUtils.CreateKeyValues(logoLayer.PresentationLayer.Position.X, 70f, RouseLib.Easing.EaseOutExpo);

                    //					var ka2 = new CAKeyFrameAnimation ();
                    //					ka2.KeyPath = "opacity";
                    //					ka2.BeginTime = 0;
                    //					ka2.Duration = 1;
                    //					ka2.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.Linear);
                    //					ka2.Values = KeyFrameUtils.CreateKeyValues (1, 0.2f, RouseLib.Easing.EaseInExpo);
                    //
                    var group = CAAnimationGroup.CreateAnimation();
                    group.BeginTime           = localTime;
                    group.Duration            = 1;
                    group.FillMode            = CAFillMode.Forwards;
                    group.RemovedOnCompletion = false;
                    group.Animations          = new CAAnimation[] { ka };
                    logoLayer.AddAnimation(group, null);
                }
            };
            View.AddSubview(moveBtn);
        }
Ejemplo n.º 15
0
 public override void AnimationStarted(CAAnimation anim)
 {
     control?.AnimationDidStart();
 }
Ejemplo n.º 16
0
 private void AnimationDidStop(CAAnimation anim, bool finished)
 {
     if (!_animationCleared)
         AnimationDelegate animationDidStop:anim shapeLayer:self finished:finished];
 }
Ejemplo n.º 17
0
        public Character()
        {
            for (int i = 0; i < StepsSoundCount; i++) {
                steps [i, (int)FloorMaterial.Grass] = SCNAudioSource.FromFile (string.Format ("game.scnassets/sounds/Step_grass_0{0}.mp3", i));
                steps [i, (int)FloorMaterial.Grass].Volume = 0.5f;
                steps [i, (int)FloorMaterial.Rock] = SCNAudioSource.FromFile (string.Format ("game.scnassets/sounds/Step_rock_0{0}.mp3", i));
                if (i < StepsInWaterSoundCount) {
                    steps [i, (int)FloorMaterial.Water] = SCNAudioSource.FromFile (string.Format ("game.scnassets/sounds/Step_splash_0{0}.mp3", i));
                    steps [i, (int)FloorMaterial.Water].Load ();
                } else {
                    steps [i, (int)FloorMaterial.Water] = steps [i % StepsInWaterSoundCount, (int)FloorMaterial.Water];
                }

                steps [i, (int)FloorMaterial.Rock].Load ();
                steps [i, (int)FloorMaterial.Grass].Load ();

                // Load the character.
                SCNScene characterScene = SCNScene.FromFile ("game.scnassets/panda.scn");
                SCNNode characterTopLevelNode = characterScene.RootNode.ChildNodes [0];

                Node = SCNNode.Create ();
                Node.AddChildNode (characterTopLevelNode);

                // Configure the "idle" animation to repeat forever
                foreach (var childNode in characterTopLevelNode.ChildNodes) {
                    foreach (var key in childNode.GetAnimationKeys ()) {
                        CAAnimation animation = childNode.GetAnimation (key);
                        animation.UsesSceneTimeBase = false;
                        animation.RepeatCount = float.PositiveInfinity;
                        childNode.AddAnimation (animation, key);
                    }
                }

                // retrieve some particle systems and save their birth rate
                fireEmitter = characterTopLevelNode.FindChildNode ("fire", true);
                fireBirthRate = fireEmitter.ParticleSystems [0].BirthRate;
                fireEmitter.ParticleSystems [0].BirthRate = 0;
                fireEmitter.Hidden = false;

                smokeEmitter = characterTopLevelNode.FindChildNode ("smoke", true);
                smokeBirthRate = smokeEmitter.ParticleSystems [0].BirthRate;
                smokeEmitter.ParticleSystems [0].BirthRate = 0;
                smokeEmitter.Hidden = false;

                whiteSmokeEmitter = characterTopLevelNode.FindChildNode ("whiteSmoke", true);
                whiteSmokeBirthRate = whiteSmokeEmitter.ParticleSystems [0].BirthRate;
                whiteSmokeEmitter.ParticleSystems [0].BirthRate = 0;
                whiteSmokeEmitter.Hidden = false;

                SCNVector3 min = SCNVector3.Zero;
                SCNVector3 max = SCNVector3.Zero;

                Node.GetBoundingBox (ref min, ref max);

                float radius = (max.X - min.X) * .4f;
                float height = (max.Y - min.Y);

                // Create a kinematic with capsule.
                SCNNode colliderNode = SCNNode.Create ();
                colliderNode.Name = "collider";
                colliderNode.Position = new SCNVector3 (0f, height * .51f, 0f);
                colliderNode.PhysicsBody = SCNPhysicsBody.CreateBody (
                    SCNPhysicsBodyType.Kinematic,
                    SCNPhysicsShape.Create (SCNCapsule.Create (radius, height))
                );

                // We want contact notifications with the collectables, enemies and walls.
                colliderNode.PhysicsBody.ContactTestBitMask = (nuint)(int)(Bitmask.SuperCollectable | Bitmask.Collectable | Bitmask.Collision | Bitmask.Enemy);
                Node.AddChildNode (colliderNode);

                walkAnimation = LoadAnimationFromSceneNamed ("game.scnassets/walk.scn");
                walkAnimation.UsesSceneTimeBase = false;
                walkAnimation.FadeInDuration = .3f;
                walkAnimation.FadeOutDuration = .3f;
                walkAnimation.RepeatCount = float.PositiveInfinity;
                walkAnimation.Speed = CharacterSpeedFactor;

                // Play foot steps at specific times in the animation
                walkAnimation.AnimationEvents = new [] {
                    SCNAnimationEvent.Create (.1f, (animation, animatedObject, playingBackward) => PlayFootStep ()),
                    SCNAnimationEvent.Create (.6f, (animation, animatedObject, playingBackward) => PlayFootStep ())
                };
            }
        }
Ejemplo n.º 18
0
        public void Draw(MTKView view)
        {
            if (!SDPlugin.IsSDKReady)
            {
                return;
            }

            // Update sizes
            if (backgroundTextureSize.Width == 0 && backgroundTextureSize.Height == 0)
            {
                var size = MakeBackgroundTextureSize();
                backgroundTextureSize = size;
                UpdateMTKViewFrame();
            }

            // Draw meshes
            if (SDPlugin.ShowMesh)
            {
                MeshController.Update();
            }

            // Get pose and tracking quality
            var localOrientation = UIApplication.SharedApplication.StatusBarOrientation;

            float[] mPoseBuffer     = new float[16];
            int     trackingQuality = 0;

            unsafe
            {
                fixed(float *ptr = &mPoseBuffer[0])
                {
                    // R T
                    // 0 1
                    int bufferSize = 16;

                    trackingQuality = SDPlugin.SixDegreesSDK_GetPose(ptr, bufferSize);
                }
            }

            if (trackingQuality > 0)
            {
                // Update camera pose
                var        row0       = new SCNVector4(mPoseBuffer[0], mPoseBuffer[1], mPoseBuffer[2], mPoseBuffer[3]);
                var        row1       = new SCNVector4(mPoseBuffer[4], mPoseBuffer[5], mPoseBuffer[6], mPoseBuffer[7]);
                var        row2       = new SCNVector4(mPoseBuffer[8], mPoseBuffer[9], mPoseBuffer[10], mPoseBuffer[11]);
                var        row3       = new SCNVector4(mPoseBuffer[12], mPoseBuffer[13], mPoseBuffer[14], mPoseBuffer[15]);
                SCNMatrix4 poseMatrix = new SCNMatrix4(row0, row1, row2, row3);

                CameraNode.WorldTransform = poseMatrix;

                // Update camera projection
                var projectionTransform = MakeProjectionMatrix(localOrientation);
                CameraNode.Camera.ProjectionTransform = projectionTransform;
            }

            // Update vertex factory
            if (vertexFactory.IsComplete == false || orientation != localOrientation)
            {
                vertexFactory.Update(localOrientation, backgroundTextureSize);
            }
            orientation = localOrientation;

            // Draw background texture
            var texturePtr = SDPlugin.SixDegreesSDK_GetBackgroundTexture();

            if (texturePtr != IntPtr.Zero)
            {
                var obj = ObjCRuntime.Runtime.GetINativeObject <IMTLTexture>(texturePtr, false);
                Draw((IMTLTexture)obj);
            }

            if (commandQueue != null)
            {
                var    commandBuffer   = commandQueue.CommandBuffer();
                var    currentDrawable = mtkView.CurrentDrawable;
                double CurrentTime     = CAAnimation.CurrentMediaTime();
                var    screenScale     = UIScreen.MainScreen.Scale;
                var    viewport        = new CGRect(x: 0, y: 0,
                                                    width: mtkView.Frame.Width * screenScale,
                                                    height: mtkView.Frame.Height * screenScale);

                var renderPassDescriptor = MTLRenderPassDescriptor.CreateRenderPassDescriptor();
                renderPassDescriptor.ColorAttachments[0].Texture     = currentDrawable.Texture;
                renderPassDescriptor.ColorAttachments[0].LoadAction  = MTLLoadAction.Load;
                renderPassDescriptor.ColorAttachments[0].StoreAction = MTLStoreAction.Store;

                renderer.Render(CurrentTime,
                                viewport,
                                commandBuffer,
                                renderPassDescriptor);

                commandBuffer.PresentDrawable(currentDrawable);
                commandBuffer.Commit();
            }
        }
Ejemplo n.º 19
0
 public override void AnimationStopped (CAAnimation anim, bool finished)
 {
     _owner.AnimationDidStop ((CABasicAnimation)anim, finished);
 }
Ejemplo n.º 20
0
 public override void AnimationStarted (CAAnimation anim)
 {
     _owner.AnimationDidStart ((CABasicAnimation)anim);
 }
Ejemplo n.º 21
0
 public override void AnimationStopped(CAAnimation anim, bool finished)
 {
     control?.AnimationDidStop();
 }
Ejemplo n.º 22
0
		public void AnimationStopped (CAAnimation anim, bool finished, IntPtr context)
		{
			this.Transform = CGAffineTransform.MakeIdentity ();
		}
Ejemplo n.º 23
0
        private void BuildImageGrid()
        {
            // Create a root node for the grid
            GroupNode = SCNNode.Create();

            // Retrieve the template node to replicate
            var scene        = SCNScene.FromFile("Contacts/contact");
            var templateNode = scene.RootNode.FindChildNode("people", true);

            for (int k = 0, j = 0; j < RowCount; j++)
            {
                for (var i = 0; i < ColumnCount; i++, k++)
                {
                    // Hierarchy : __groupNode > container > node
                    var container = SCNNode.Create();
                    var node      = templateNode.Clone();
                    node.Name = "contact" + k;

                    GroupNode.AddChildNode(container);
                    container.AddChildNode(node);

                    if (k == 28)
                    {
                        HeroNode = node;
                    }

                    // Curved layout
                    var angle = 0.12f * ((ColumnCount - 1) / 2.0f - i);
                    var x     = NMath.Cos(angle + (float)(Math.PI / 2)) * 500.0f;
                    var z     = NMath.Sin(angle + (float)(Math.PI / 2)) * 500.0f;
                    container.Position = new SCNVector3(x, j * 60, -z + 400);
                    container.Rotation = new SCNVector4(0, 1, 0, angle);

                    // We want a different image on each elemement and to do that we need to
                    // unshare the geometry first and then unshare the material

                    var geometryNode = node.ChildNodes [0];
                    geometryNode.Geometry = (SCNGeometry)geometryNode.Geometry.Copy();

                    var materialCopy = (SCNMaterial)geometryNode.Geometry.Materials [1].Copy();
                    materialCopy.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Contacts/contact" + (k % ContactImageCount), "jpg"));
                    geometryNode.Geometry.ReplaceMaterial(1, materialCopy);

                    // Animate (rotate forever)
                    var animation = CAKeyFrameAnimation.GetFromKeyPath("rotation");
                    animation.Duration = 4.0f;
                    animation.KeyTimes = new NSNumber[] { 0.0f, 0.3f, 1.0f };
                    animation.Values   = new NSObject[] { NSValue.FromVector(new SCNVector4(0, 1, 0, 0)),
                                                          NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))),
                                                          NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))) };

                    var tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                    animation.TimingFunctions = new CAMediaTimingFunction[] { tf, tf, tf };
                    animation.RepeatCount     = float.MaxValue;
                    animation.BeginTime       = CAAnimation.CurrentMediaTime() + 1.0f + j * 0.1f + i * 0.05f;                // desynchronize the animations
                    node.AddAnimation(animation, new NSString("animation"));
                }
            }

            // Add the group to the scene
            GroupNode.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            GroupNode.Position = new SCNVector3(0, Altitude - 2.8f, 18);
            GroupNode.Opacity  = 0.0f;

            GroundNode.AddChildNode(GroupNode);
        }
Ejemplo n.º 24
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case (int)ParticleSteps.Fire:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);

                TextManager.AddEmptyLine();
                TextManager.AddBulletAtLevel("Particle Image", 0);
                TextManager.AddBulletAtLevel("Color over life duration", 0);
                TextManager.AddBulletAtLevel("Size over life duration", 0);
                TextManager.AddBulletAtLevel("Several blend modes", 0);

                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                var hole = SCNNode.Create();
                hole.Geometry = SCNTube.Create(1.7f, 1.9f, 1.5f);
                hole.Position = new SCNVector3(0, 0, HOLE_Z);
                hole.Scale    = new SCNVector3(1, 0, 1);

                GroundNode.AddChildNode(hole);

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.5f;

                hole.Scale = new SCNVector3(1, 1, 1);

                SCNTransaction.Commit();

                var ps = SCNParticleSystem.Create("fire", "Particles");
                hole.AddParticleSystem(ps);

                Hole = hole;
                break;

            case (int)ParticleSteps.FireScreen:
                ps           = Hole.ParticleSystems [0];
                ps.BlendMode = SCNParticleBlendMode.Screen;
                break;

            case (int)ParticleSteps.Local:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);

                TextManager.AddBulletAtLevel("Local vs Global", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                Hole.RemoveAllParticleSystems();
                Hole2          = Hole.Clone();
                Hole2.Geometry = (SCNGeometry)Hole.Geometry.Copy();
                Hole2.Position = new SCNVector3(0, -2, HOLE_Z - 4);
                GroundNode.AddChildNode(Hole2);
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.5;
                Hole2.Position = new SCNVector3(0, 0, HOLE_Z - 4);
                SCNTransaction.Commit();

                ps = SCNParticleSystem.Create("reactor", "Particles");
                ps.ParticleColorVariation = new SCNVector4(0, 0, 0.5f, 0);
                Hole.AddParticleSystem(ps);

                var localPs = (SCNParticleSystem)ps.Copy();
                localPs.ParticleImage = ps.ParticleImage;
                localPs.Local         = true;
                Hole2.AddParticleSystem(localPs);

                var animation = CABasicAnimation.FromKeyPath("position");
                animation.From           = NSValue.FromVector(new SCNVector3(7, 0, HOLE_Z));
                animation.To             = NSValue.FromVector(new SCNVector3(-7, 0, HOLE_Z));
                animation.BeginTime      = CAAnimation.CurrentMediaTime() + 0.75;
                animation.Duration       = 8;
                animation.AutoReverses   = true;
                animation.RepeatCount    = float.MaxValue;
                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimeOffset     = animation.Duration / 2;
                Hole.AddAnimation(animation, new NSString("animateHole"));

                animation                = CABasicAnimation.FromKeyPath("position");
                animation.From           = NSValue.FromVector(new SCNVector3(-7, 0, HOLE_Z - 4));
                animation.To             = NSValue.FromVector(new SCNVector3(7, 0, HOLE_Z - 4));
                animation.BeginTime      = CAAnimation.CurrentMediaTime() + 0.75;
                animation.Duration       = 8;
                animation.AutoReverses   = true;
                animation.RepeatCount    = float.MaxValue;
                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimeOffset     = animation.Duration / 2;
                Hole2.AddAnimation(animation, new NSString("animateHole"));
                break;

            case (int)ParticleSteps.Gravity:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);

                TextManager.AddBulletAtLevel("Affected by gravity", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                Hole2.RemoveAllParticleSystems();
                Hole2.RunAction(SCNAction.Sequence(new SCNAction[] {
                    SCNAction.ScaleTo(0, 0.5),
                    SCNAction.RemoveFromParentNode()
                }));
                Hole.RemoveAllParticleSystems();
                Hole.RemoveAnimation(new NSString("animateHole"), 0.5f);

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.5;

                var tube = (SCNTube)Hole.Geometry;
                tube.InnerRadius = 0.3f;
                tube.OuterRadius = 0.4f;
                tube.Height      = 1.0f;

                SCNTransaction.Commit();

                ps = SCNParticleSystem.Create("sparks", "Particles");
                Hole.RemoveAllParticleSystems();
                Hole.AddParticleSystem(ps);

                foreach (var child in ((SCNView)presentationViewController.View).Scene.RootNode.ChildNodes)
                {
                    if (child.Geometry != null)
                    {
                        if (child.Geometry.GetType() == typeof(SCNFloor))
                        {
                            FloorNode = child;
                        }
                    }
                }

                /*FloorNode = ((SCNView)presentationViewController.View).Scene.RootNode.FindNodes ((SCNNode child, out bool stop) => {
                 *      stop = false;
                 *      if (child.Geometry != null)
                 *              stop = (child.Geometry.GetType () == typeof(SCNFloor));
                 *      return stop;
                 * });*/

                /*FloorNode = [presentationViewController.view.scene.rootNode childNodesPassingTest:^BOOL(SCNNode *child, BOOL *stop) {
                 *      return [child.geometry isKindOfClass:[SCNFloor class]];
                 * }][0];*/

                ps.ColliderNodes = new SCNNode[] { FloorNode };

                break;

            case (int)ParticleSteps.Collider:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);

                TextManager.AddBulletAtLevel("Affected by colliders", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                var boxNode = SCNNode.Create();
                boxNode.Geometry = SCNBox.Create(5, 0.2f, 5, 0);
                boxNode.Position = new SCNVector3(0, 7, HOLE_Z);
                boxNode.Geometry.FirstMaterial.Emission.Contents = NSColor.DarkGray;

                GroundNode.AddChildNode(boxNode);

                ps = Hole.ParticleSystems [0];
                ps.ColliderNodes = new SCNNode[] { FloorNode, boxNode };

                animation                = CABasicAnimation.FromKeyPath("eulerAngles");
                animation.From           = NSValue.FromVector(new SCNVector3(0, 0, NMath.PI / 4 * 1.7f));
                animation.To             = NSValue.FromVector(new SCNVector3(0, 0, -NMath.PI / 4 * 1.7f));
                animation.BeginTime      = CAAnimation.CurrentMediaTime() + 0.5;
                animation.Duration       = 2;
                animation.AutoReverses   = true;
                animation.RepeatCount    = float.MaxValue;
                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimeOffset     = animation.Duration / 2;
                boxNode.AddAnimation(animation, new NSString("animateHole"));

                BoxNode = boxNode;
                break;

            case (int)ParticleSteps.Fields:
                Hole.RemoveAllParticleSystems();

                Hole.RunAction(SCNAction.Sequence(new SCNAction[] {
                    SCNAction.ScaleTo(0, 0.75),
                    SCNAction.RemoveFromParentNode()
                }));

                BoxNode.RunAction(SCNAction.Sequence(new SCNAction[] {
                    SCNAction.MoveBy(0, 15, 0, 1.0),
                    SCNAction.RemoveFromParentNode()
                }));

                var particleHolder = SCNNode.Create();
                particleHolder.Position = new SCNVector3(0, 20, HOLE_Z);
                GroundNode.AddChildNode(particleHolder);

                ParticleHolder = particleHolder;

                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.AddBulletAtLevel("Affected by physics fields", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                ps = SCNParticleSystem.Create("snow", "Particles");
                ps.AffectedByPhysicsFields = true;
                ParticleHolder.AddParticleSystem(ps);
                Snow = ps;

                //physics field
                var field = SCNPhysicsField.CreateTurbulenceField(50, 1);
                field.HalfExtent = new SCNVector3(20, 20, 20);
                field.Strength   = 4.0f;

                var fieldOwner = SCNNode.Create();
                fieldOwner.Position = new SCNVector3(0, 5, HOLE_Z);

                GroundNode.AddChildNode(fieldOwner);
                fieldOwner.PhysicsField = field;
                FieldOwner = fieldOwner;

                ps.ColliderNodes = new SCNNode[] { FloorNode };
                break;

            case (int)ParticleSteps.FieldsVortex:
                VortexFieldOwner          = SCNNode.Create();
                VortexFieldOwner.Position = new SCNVector3(0, 5, HOLE_Z);

                GroundNode.AddChildNode(VortexFieldOwner);

                //tornado
                var worldOrigin = new SCNVector3(FieldOwner.WorldTransform.M41, FieldOwner.WorldTransform.M42, FieldOwner.WorldTransform.M43);
                var worldAxis   = new SCNVector3(0, 1, 0);

                var vortex = SCNPhysicsField.CustomField((SCNVector3 position, SCNVector3 velocity, float mass, float charge, double timeInSeconds) => {
                    var l        = new SCNVector3();
                    l.X          = worldOrigin.X - position.X;
                    l.Z          = worldOrigin.Z - position.Z;
                    SCNVector3 t = Cross(worldAxis, l);
                    var d2       = (l.X * l.X + l.Z * l.Z);
                    var vs       = (nfloat)(VS / Math.Sqrt(d2));
                    var fy       = (nfloat)(1.0 - (Math.Min(1.0, (position.Y / 15.0))));
                    return(new SCNVector3(t.X * vs + l.X * (nfloat)VW * fy, 0, t.Z * vs + l.Z * (nfloat)VW * fy));
                });
                vortex.HalfExtent             = new SCNVector3(100, 100, 100);
                VortexFieldOwner.PhysicsField = vortex;
                break;

            case (int)ParticleSteps.SubSystems:
                FieldOwner.RemoveFromParentNode();
                ParticleHolder.RemoveAllParticleSystems();
                Snow.DampingFactor = -1;

                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.AddBulletAtLevel("Sub-particle system on collision", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                ps = SCNParticleSystem.Create("rain", "Particles");
                var pss = SCNParticleSystem.Create("plok", "Particles");
                pss.IdleDuration = 0;
                pss.Loops        = false;

                ps.SystemSpawnedOnCollision = pss;

                ParticleHolder.AddParticleSystem(ps);
                ps.ColliderNodes = new SCNNode[] { FloorNode };
                break;

            case (int)ParticleSteps.Confetti:
                ParticleHolder.RemoveAllParticleSystems();

                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.AddBulletAtLevel("Custom blocks", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                ps = SCNParticleSystem.Create();
                ps.EmitterShape                     = SCNBox.Create(20, 9, 5, 0);
                ps.BirthRate                        = 100;
                ps.ParticleLifeSpan                 = 10;
                ps.ParticleLifeSpanVariation        = 0;
                ps.SpreadingAngle                   = 20;
                ps.ParticleSize                     = 0.25f;
                ps.ParticleVelocity                 = 10;
                ps.ParticleVelocityVariation        = 19;
                ps.BirthDirection                   = SCNParticleBirthDirection.Constant;
                ps.EmittingDirection                = new SCNVector3(0, -1, 0);
                ps.BirthLocation                    = SCNParticleBirthLocation.Volume;
                ps.ParticleImage                    = new NSImage(NSBundle.MainBundle.PathForResource("Particles/confetti", "png"));
                ps.LightingEnabled                  = true;
                ps.OrientationMode                  = SCNParticleOrientationMode.Free;
                ps.SortingMode                      = SCNParticleSortingMode.Distance;
                ps.ParticleAngleVariation           = 180;
                ps.ParticleAngularVelocity          = 200;
                ps.ParticleAngularVelocityVariation = 400;
                ps.ParticleColor                    = NSColor.Green;
                ps.ParticleColorVariation           = new SCNVector4(0.2f, 0.1f, 0.1f, 0);
                ps.ParticleBounce                   = 0;
                ps.ParticleFriction                 = 0.6f;
                ps.ColliderNodes                    = new SCNNode[] { FloorNode };
                ps.BlendMode                        = SCNParticleBlendMode.Alpha;

                var floatAnimation = CAKeyFrameAnimation.FromKeyPath("");
                floatAnimation.Values   = new NSNumber[] { 1, 1, 0 };
                floatAnimation.KeyTimes = new NSNumber[] { 0, 0.9f, 1 };
                floatAnimation.Duration = 1.0f;
                floatAnimation.Additive = false;

                //ps.PropertyControllers = @{ SCNParticlePropertyOpacity: [SCNParticlePropertyController controllerWithAnimation:floatAnimation] };
                //ps.HandleEvent (SCNParticleEvent.Birth,

                /*[ps handleEvent:SCNParticleEventBirth forProperties:@[SCNParticlePropertyColor] withBlock:^(void **data, size_t *dataStride, uint32_t *indices , NSInteger count) {
                 *
                 *      for (int i = 0; i < count; ++i) {
                 *              var col = (float *)((char *)data[0] + dataStride[0] * i);
                 *              if (rand() & 0x1) { // swith green for red
                 *                      col[0] = col[1];
                 *                      col[1] = 0;
                 *              }
                 *
                 *      }
                 * }];*/

                /*[ps handleEvent:SCNParticleEventCollision forProperties:@[SCNParticlePropertyAngle, SCNParticlePropertyRotationAxis, SCNParticlePropertyAngularVelocity, SCNParticlePropertyVelocity, SCNParticlePropertyContactNormal] withBlock:^(void **data, size_t *dataStride, uint32_t *indices , NSInteger count) {
                 *
                 *      for (NSInteger i = 0; i < count; ++i) {
                 *              // fix orientation
                 *              float *angle = (float *)((char *)data[0] + dataStride[0] * indices[i]);
                 *              float *axis = (float *)((char *)data[1] + dataStride[1] * indices[i]);
                 *
                 *              float *colNrm = (float *)((char *)data[4] + dataStride[4] * indices[i]);
                 *              SCNVector3 collisionNormal = {colNrm[0], colNrm[1], colNrm[2]};
                 *              SCNVector3 cp = SCNVector3CrossProduct(collisionNormal, SCNVector3Make(0, 0, 1));
                 *              CGFloat cpLen = SCNVector3Length(cp);
                 *              angle[0] = asin(cpLen);
                 *
                 *              axis[0] = cp.x / cpLen;
                 *              axis[1] = cp.y / cpLen;
                 *              axis[2] = cp.z / cpLen;
                 *
                 *              // kill angular rotation
                 *              float *angVel = (float *)((char *)data[2] + dataStride[2] * indices[i]);
                 *              angVel[0] = 0;
                 *
                 *              if (colNrm[1] > 0.4) {
                 *                      float *vel = (float *)((char *)data[3] + dataStride[3] * indices[i]);
                 *                      vel[0] = 0;
                 *                      vel[1] = 0;
                 *                      vel[2] = 0;
                 *              }
                 *      }
                 * }];*/

                ParticleHolder.AddParticleSystem(ps);
                break;

            case (int)ParticleSteps.EmitterCube:
                ParticleHolder.RemoveAllParticleSystems();

                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.AddBulletAtLevel("Emitter shape", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);

                ParticleHolder.RemoveFromParentNode();

                ps       = SCNParticleSystem.Create("emitters", "Particles");
                ps.Local = true;
                ParticleHolder.AddParticleSystem(ps);

                var node = SCNNode.Create();
                node.Position = new SCNVector3(3, 6, HOLE_Z);
                node.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(NMath.PI * 2, new SCNVector3(0.3f, 1, 0), 8)));
                GroundNode.AddChildNode(node);
                Bokeh = ps;

                node.AddParticleSystem(ps);
                break;

            case (int)ParticleSteps.EmitterSphere:
                Bokeh.EmitterShape = SCNSphere.Create(5);
                break;

            case (int)ParticleSteps.EmitterTorus:
                Bokeh.EmitterShape = SCNTorus.Create(5, 1);
                break;
            }
        }
 public override void AnimationStopped(CAAnimation anim, bool finished)
 {
     //throw new NotImplementedException();
 }
Ejemplo n.º 26
0
		private void ExtractAnimation (SCNSceneSource sceneSource)
		{
			// In this scene objects are animated separately using long animations
			// playing 3 successive animations. We will group these long animations
			// and then split the group in 3 different animation groups.
			// We could also have used three DAEs (one per animation).

			var animationIDs = sceneSource.GetIdentifiersOfEntries (new Class ("CAAnimation"));

			var animationCount = animationIDs.Length;
			var longAnimations = new CAAnimation [animationCount];

			var maxDuration = 0.0;

			for (var index = 0; index < animationCount; index++) {
				var animation = (CAAnimation)sceneSource.GetEntryWithIdentifier (animationIDs [index].ToString (), new Class ("CAAnimation"));
				if (animation != null) {
					maxDuration = Math.Max (maxDuration, animation.Duration);
					longAnimations [index] = animation;
				}
			}

			var longAnimationsGroup = new CAAnimationGroup ();
			longAnimationsGroup.Animations = longAnimations;
			longAnimationsGroup.Duration = maxDuration;

			var idleAnimationGroup = (CAAnimationGroup)longAnimationsGroup.Copy ();
			idleAnimationGroup.TimeOffset = 6.45833333333333f;
			IdleAnimationGroup = CAAnimationGroup.CreateAnimation ();
			IdleAnimationGroup.Animations = new CAAnimation[] { idleAnimationGroup };
			IdleAnimationGroup.Duration = 24.71f - 6.45833333333333f;
			IdleAnimationGroup.RepeatCount = float.MaxValue;
			IdleAnimationGroup.AutoReverses = true;

			var animationGroup1 = (CAAnimationGroup)longAnimationsGroup.Copy ();
			AnimationGroup1 = CAAnimationGroup.CreateAnimation ();
			AnimationGroup1.Animations = new CAAnimation[] { animationGroup1 };
			AnimationGroup1.Duration = 1.4f;
			animationGroup1.FadeInDuration = 0.1f;
			animationGroup1.FadeOutDuration = 0.5f;

			var animationGroup2 = (CAAnimationGroup)longAnimationsGroup.Copy ();
			animationGroup2.TimeOffset = 3.666666666666667f;
			AnimationGroup2 = CAAnimationGroup.CreateAnimation ();
			AnimationGroup2.Animations = new CAAnimation[] { animationGroup2 };
			AnimationGroup2.Duration = 6.416666666666667f - 3.666666666666667f;
			animationGroup2.FadeInDuration = 0.1f;
			animationGroup2.FadeOutDuration = 0.5f;
		}
Ejemplo n.º 27
0
            public override void AnimationStopped(CAAnimation anim, bool finished)
            {
                if (finished)
                {
                    if (!_bemCheckBox.On)
                    {
                        _bemCheckBox._onBoxLayer.RemoveFromSuperLayer();
                        _bemCheckBox._checkMarkLayer.RemoveFromSuperLayer();
                    }

                }
            }
 public override void AnimationStopped(CAAnimation anim, bool finished)
 {
     ctrl.transitioning = false;
 }
Ejemplo n.º 29
0
 public static void Animate(this UIView view, CAAnimation animation, bool finished)
 {
     view.Layer.AnimationDidStop(animation, finished);
 }
Ejemplo n.º 30
0
        private void OnAnimationDidStop(CAAnimation anim, bool flag)
        {
            if (flag)
            {
                if (anim.ForKey == ANIM_STARTBASE)
                {
                    mSlideLayer.RemoveAllAnimations();
                    mSlideLayer.IsAnimating = true;
                    CAKeyFrameAnimation animSpring =
                        new CAKeyFrameAnimation("distance", 0, mSlideLayer.BackgroundWidth, 2f);
                    Damp damp = new Damp();
                    damp.Damping              = 0.5f;
                    damp.Velocity             = 3f;
                    animSpring.EasingFunction = damp;
                    animSpring.ForKey         = ANIM_STARTSPRING;
                    mSlideLayer.AddAnimation(animSpring);
                    //CAKeyframeAnimation animCircle = [self createBaseAnima: @"radius" duration: .8f fromValue:@(0) toValue:@(sqrt(_circleLayer.frame.size.width * _circleLayer.frame.size.width + _circleLayer.frame.size.height * _circleLayer.frame.size.width))];
                    //[_circleLayer addAnimation:animCircle forKey:ANIM_STARTCIRCLE];
                    return;
                }

                if (anim.ForKey == ANIM_STARTSPRING)
                {
                    mSlideLayer.Distance = mSlideLayer.BackgroundWidth;
                    mSlideLayer.RemoveAllAnimations();
                    return;
                }

                if (anim.ForKey == ANIM_STARTCIRCLE)
                {
                    //_circleLayer.radius = sqrt(_circleLayer.frame.size.width * _circleLayer.frame.size.width + _circleLayer.frame.size.height * _circleLayer.frame.size.width);
                    //    [_circleLayer removeAllAnimations];
                    return;
                }

                if (anim.ForKey == ANIM_ENDBASE)
                {
                    mSlideLayer.RemoveAllAnimations();
                    mSlideLayer.Distance    = mSlideLayer.BackgroundWidth;
                    mSlideLayer.IsAnimating = false;
                    CAKeyFrameAnimation animSpring =
                        new CAKeyFrameAnimation("distance", mSlideLayer.BackgroundWidth, 0, 2f);
                    Damp damp = new Damp();
                    damp.Damping              = 0.5f;
                    damp.Velocity             = 3f;
                    animSpring.EasingFunction = damp;
                    animSpring.ForKey         = ANIM_ENDSPRING;
                    mSlideLayer.AddAnimation(animSpring);
                }

                if (anim.ForKey == ANIM_ENDSPRING)
                {
                    mSlideLayer.Distance = 0;
                    mSlideLayer.RemoveAllAnimations();
                }

                if (anim.ForKey == ANIM_ENDCIRCLE)
                {
                    //_circleLayer.radius = 0;
                    //    [_circleLayer removeAllAnimations];
                }
            }
            else
            {
                mSlideLayer.Distance = 0;
                mSlideLayer.RemoveAllAnimations();
            }
        }
Ejemplo n.º 31
0
		void AnimateBack (UIView view, CAAnimation animation)
		{
			if (view == null)
				return;
			
			var b = view.Bounds;
			view.Layer.Position = new PointF (b.Width/2, b.Height/2);
			view.Layer.AddAnimation (animation, "position");
		}
Ejemplo n.º 32
0
 private AnimationChain(CALayer layer, CAAnimation animation)
 {
     _layer     = layer;
     _animation = animation;
 }
Ejemplo n.º 33
0
        public Character()
        {
            for (int i = 0; i < StepsSoundCount; i++)
            {
                steps [i, (int)FloorMaterial.Grass]        = SCNAudioSource.FromFile(string.Format("game.scnassets/sounds/Step_grass_0{0}.mp3", i));
                steps [i, (int)FloorMaterial.Grass].Volume = 0.5f;
                steps [i, (int)FloorMaterial.Rock]         = SCNAudioSource.FromFile(string.Format("game.scnassets/sounds/Step_rock_0{0}.mp3", i));
                if (i < StepsInWaterSoundCount)
                {
                    steps [i, (int)FloorMaterial.Water] = SCNAudioSource.FromFile(string.Format("game.scnassets/sounds/Step_splash_0{0}.mp3", i));
                    steps [i, (int)FloorMaterial.Water].Load();
                }
                else
                {
                    steps [i, (int)FloorMaterial.Water] = steps [i % StepsInWaterSoundCount, (int)FloorMaterial.Water];
                }

                steps [i, (int)FloorMaterial.Rock].Load();
                steps [i, (int)FloorMaterial.Grass].Load();

                // Load the character.
                SCNScene characterScene        = SCNScene.FromFile("game.scnassets/panda.scn");
                SCNNode  characterTopLevelNode = characterScene.RootNode.ChildNodes [0];

                Node = SCNNode.Create();
                Node.AddChildNode(characterTopLevelNode);

                // Configure the "idle" animation to repeat forever
                foreach (var childNode in characterTopLevelNode.ChildNodes)
                {
                    foreach (var key in childNode.GetAnimationKeys())
                    {
                        CAAnimation animation = childNode.GetAnimation(key);
                        animation.UsesSceneTimeBase = false;
                        animation.RepeatCount       = float.PositiveInfinity;
                        childNode.AddAnimation(animation, key);
                    }
                }

                // retrieve some particle systems and save their birth rate
                fireEmitter   = characterTopLevelNode.FindChildNode("fire", true);
                fireBirthRate = fireEmitter.ParticleSystems [0].BirthRate;
                fireEmitter.ParticleSystems [0].BirthRate = 0;
                fireEmitter.Hidden = false;

                smokeEmitter   = characterTopLevelNode.FindChildNode("smoke", true);
                smokeBirthRate = smokeEmitter.ParticleSystems [0].BirthRate;
                smokeEmitter.ParticleSystems [0].BirthRate = 0;
                smokeEmitter.Hidden = false;

                whiteSmokeEmitter   = characterTopLevelNode.FindChildNode("whiteSmoke", true);
                whiteSmokeBirthRate = whiteSmokeEmitter.ParticleSystems [0].BirthRate;
                whiteSmokeEmitter.ParticleSystems [0].BirthRate = 0;
                whiteSmokeEmitter.Hidden = false;

                SCNVector3 min = SCNVector3.Zero;
                SCNVector3 max = SCNVector3.Zero;

                Node.GetBoundingBox(ref min, ref max);

                float radius = (max.X - min.X) * .4f;
                float height = (max.Y - min.Y);

                // Create a kinematic with capsule.
                SCNNode colliderNode = SCNNode.Create();
                colliderNode.Name        = "collider";
                colliderNode.Position    = new SCNVector3(0f, height * .51f, 0f);
                colliderNode.PhysicsBody = SCNPhysicsBody.CreateBody(
                    SCNPhysicsBodyType.Kinematic,
                    SCNPhysicsShape.Create(SCNCapsule.Create(radius, height))
                    );

                // We want contact notifications with the collectables, enemies and walls.
                colliderNode.PhysicsBody.ContactTestBitMask = (nuint)(int)(Bitmask.SuperCollectable | Bitmask.Collectable | Bitmask.Collision | Bitmask.Enemy);
                Node.AddChildNode(colliderNode);

                walkAnimation = LoadAnimationFromSceneNamed("game.scnassets/walk.scn");
                walkAnimation.UsesSceneTimeBase = false;
                walkAnimation.FadeInDuration    = .3f;
                walkAnimation.FadeOutDuration   = .3f;
                walkAnimation.RepeatCount       = float.PositiveInfinity;
                walkAnimation.Speed             = CharacterSpeedFactor;

                // Play foot steps at specific times in the animation
                walkAnimation.AnimationEvents = new [] {
                    SCNAnimationEvent.Create(.1f, (animation, animatedObject, playingBackward) => PlayFootStep()),
                    SCNAnimationEvent.Create(.6f, (animation, animatedObject, playingBackward) => PlayFootStep())
                };
            }
        }
Ejemplo n.º 34
0
 public static AnimationChain Create(CALayer layer, CAAnimation animation)
 {
     return(new AnimationChain(layer, animation));
 }
Ejemplo n.º 35
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                // Hide everything (in case the user went backward)
                for (var i = 1; i < 4; i++)
                {
                    var teapot = GroundNode.FindChildNode("Teapot" + i, true);
                    teapot.Opacity = 0.0f;
                }
                break;

            case 1:
                // Move the camera and adjust the clipping plane
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 3;
                presentationViewController.CameraNode.Position    = new SCNVector3(0, 0, 200);
                presentationViewController.CameraNode.Camera.ZFar = 500.0f;
                SCNTransaction.Commit();
                break;

            case 2:
                // Revert to original position
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                presentationViewController.CameraNode.Position    = new SCNVector3(0, 0, 0);
                presentationViewController.CameraNode.Camera.ZFar = 100.0f;
                SCNTransaction.Commit();
                break;

            case 3:
                var numberNodes = new SCNNode[] { AddNumberNode("64k", -17),
                                                  AddNumberNode("6k", -9),
                                                  AddNumberNode("3k", -1),
                                                  AddNumberNode("1k", 6.5f),
                                                  AddNumberNode("256", 14) };
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;

                // Move the camera and the text
                presentationViewController.CameraHandle.Position = new SCNVector3(presentationViewController.CameraHandle.Position.X, presentationViewController.CameraHandle.Position.Y + 6, presentationViewController.CameraHandle.Position.Z);
                TextManager.TextNode.Position = new SCNVector3(TextManager.TextNode.Position.X, TextManager.TextNode.Position.Y + 6, TextManager.TextNode.Position.Z);

                // Show the remaining resolutions
                for (var i = 0; i < 5; i++)
                {
                    var numberNode = numberNodes [i];
                    numberNode.Position = new SCNVector3(numberNode.Position.X, 7, -5);

                    var teapot = GroundNode.FindChildNode("Teapot" + i, true);
                    teapot.Opacity  = 1.0f;
                    teapot.Rotation = new SCNVector4(0, 0, 1, (float)(Math.PI / 4));
                    teapot.Position = new SCNVector3((i - 2) * 8, 5, teapot.Position.Z);
                }

                SCNTransaction.Commit();
                break;

            case 4:
                presentationViewController.ShowsNewInSceneKitBadge(true);

                // Remove the numbers
                RemoveNumberNodes();

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                // Add some text and code
                TextManager.SetSubtitle("SCNLevelOfDetail");

                TextManager.AddCode("#var lod1 = SCNLevelOfDetail.#CreateWithWorldSpaceDistance# (aGeometry, aDistance); \n"
                                    + "geometry.#LevelsOfDetail# = new SCNLevelOfDetail { lod1, lod2, ..., lodn };#");

                // Animation the merge
                for (int i = 0; i < 5; i++)
                {
                    var teapot = GroundNode.FindChildNode("Teapot" + i, true);

                    teapot.Opacity  = i == 0 ? 1.0f : 0.0f;
                    teapot.Rotation = new SCNVector4(0, 0, 1, 0);
                    teapot.Position = new SCNVector3(0, -5, teapot.Position.Z);
                }

                // Move the camera and the text
                presentationViewController.CameraHandle.Position = new SCNVector3(presentationViewController.CameraHandle.Position.X, presentationViewController.CameraHandle.Position.Y - 3, presentationViewController.CameraHandle.Position.Z);
                TextManager.TextNode.Position = new SCNVector3(TextManager.TextNode.Position.X, TextManager.TextNode.Position.Y - 3, TextManager.TextNode.Position.Z);

                SCNTransaction.Commit();
                break;

            case 5:
                presentationViewController.ShowsNewInSceneKitBadge(false);

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 3;
                // Change the lighting to remove the front light and rise the main light
                presentationViewController.UpdateLightingWithIntensities(new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.3f });
                presentationViewController.RiseMainLight(true);

                // Remove some text
                TextManager.FadeOutText(SlideTextManager.TextType.Title);
                TextManager.FadeOutText(SlideTextManager.TextType.Subtitle);
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                SCNTransaction.Commit();

                // Retrieve the main teapot
                var maintTeapot = GroundNode.FindChildNode("Teapot0", true);

                // The distances to use for each LOD
                var distances = new float[] { 30, 50, 90, 150 };

                // An array of SCNLevelOfDetail instances that we will build
                var levelsOfDetail = new SCNLevelOfDetail[4];
                for (var i = 1; i < 5; i++)
                {
                    var teapotNode = GroundNode.FindChildNode("Teapot" + i, true);
                    var teapot     = teapotNode.Geometry;

                    // Unshare the material because we will highlight the different levels of detail with different colors in the next step
                    teapot.FirstMaterial = (SCNMaterial)teapot.FirstMaterial.Copy();

                    // Build the SCNLevelOfDetail instance
                    var levelOfDetail = SCNLevelOfDetail.CreateWithWorldSpaceDistance(teapot, distances [i - 1]);
                    levelsOfDetail [i - 1] = levelOfDetail;
                }

                maintTeapot.Geometry.LevelsOfDetail = levelsOfDetail;

                // Duplicate and move the teapots
                var startTime = CAAnimation.CurrentMediaTime();
                var delay     = 0.2;

                var rowCount    = 9;
                var columnCount = 12;

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0;
                // Change the far clipping plane to be able to see far away
                presentationViewController.CameraNode.Camera.ZFar = 1000.0;

                for (var j = 0; j < columnCount; j++)
                {
                    for (var i = 0; i < rowCount; i++)
                    {
                        // Clone
                        var clone = maintTeapot.Clone();
                        maintTeapot.ParentNode.AddChildNode(clone);

                        // Animate
                        var animation = CABasicAnimation.FromKeyPath("position");
                        animation.Additive  = true;
                        animation.Duration  = 1.0;
                        animation.To        = NSValue.FromVector(new SCNVector3((i - rowCount / 2.0f) * 12.0f, 5 + (columnCount - j) * 15.0f, 0));
                        animation.From      = NSValue.FromVector(new SCNVector3(0, 0, 0));
                        animation.BeginTime = startTime + delay;                         // desynchronize

                        // Freeze at the end of the animation
                        animation.RemovedOnCompletion = false;
                        animation.FillMode            = CAFillMode.Forwards;

                        clone.AddAnimation(animation, new NSString("cloneAnimation"));

                        // Animate the hidden property to automatically show the node when the position animation starts
                        animation          = CABasicAnimation.FromKeyPath("hidden");
                        animation.Duration = delay + 0.01;
                        animation.FillMode = CAFillMode.Both;
                        animation.From     = new NSNumber(1);
                        animation.To       = new NSNumber(0);
                        clone.AddAnimation(animation, new NSString("cloneAnimation2"));

                        delay += 0.05;
                    }
                }
                SCNTransaction.Commit();

                // Animate the camera while we duplicate the nodes
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1.0 + rowCount * columnCount * 0.05;

                var position = presentationViewController.CameraHandle.Position;
                presentationViewController.CameraHandle.Position = new SCNVector3(position.X, position.Y + 5, position.Z);
                presentationViewController.CameraPitch.Rotation  = new SCNVector4(1, 0, 0, presentationViewController.CameraPitch.Rotation.W - ((float)(Math.PI / 4) * 0.1f));
                SCNTransaction.Commit();
                break;

            case 6:
                // Highlight the levels of detail with colors
                var teapotChild = GroundNode.FindChildNode("Teapot0", true);
                var colors      = new NSColor[] { NSColor.Red, NSColor.Orange, NSColor.Yellow, NSColor.Green };

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                for (var i = 0; i < 4; i++)
                {
                    var levelOfDetail = teapotChild.Geometry.LevelsOfDetail [i];
                    levelOfDetail.Geometry.FirstMaterial.Multiply.Contents = colors [i];
                }
                SCNTransaction.Commit();
                break;
            }
        }
			public override void AnimationStopped (CAAnimation anim, bool finished)
			{
				_transitionContext.CompleteTransition (!_transitionContext.TransitionWasCancelled);
				var fromCont = _transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as UIViewController;
				fromCont.View.Layer.Mask = null;
			}
Ejemplo n.º 37
0
		public void AnimationStarted (CAAnimation anim, IntPtr context)
		{
		}
Ejemplo n.º 38
0
		void AttachFadeoutAnimation (CALayer progress, CAAnimation animation, Func<bool> fadeoutVerifier)
		{
			animation.AnimationStopped += (sender, e) => {
				if (!fadeoutVerifier ())
					return;

				CABasicAnimation fadeout = CABasicAnimation.FromKeyPath ("opacity");
				fadeout.From = NSNumber.FromDouble (1);
				fadeout.To = NSNumber.FromDouble (0);
				fadeout.Duration = 0.5;
				fadeout.FillMode = CAFillMode.Forwards;
				fadeout.RemovedOnCompletion = false;
				fadeout.AnimationStopped += (sender2, e2) => {
					if (!e2.Finished)
						return;

					inProgress = false;
					progress.Opacity = 0;
					progress.RemoveAllAnimations ();
					progress.RemoveFromSuperLayer ();
				};
				progress.Name = ProgressLayerFadingId;
				progress.AddAnimation (fadeout, "opacity");
			};
			progress.AddAnimation (animation, growthAnimationKey);
			var oldLayer = ProgressLayer;
			if (oldLayer == null)
				Layer.AddSublayer (progress);

			UpdateLayer ();
		}
Ejemplo n.º 39
0
 public override void AnimationStopped(CAAnimation anim, bool finished)
 {
     _owner.AnimationDidStop((CABasicAnimation)anim, finished);
 }
Ejemplo n.º 40
0
		void ThrowCoconut (CAAnimation animation, NSObject animatedObject, bool playingBackward)
		{
			if (!hasCoconut)
				return;

			SCNMatrix4 worldMtx = coconutInHand.PresentationNode.WorldTransform;
			coconutInHand.RemoveFromParentNode ();

			Coconut node = Coconut.CoconutThrowProtoObject;
			SCNPhysicsShape coconutPhysicsShape = Coconut.CoconutPhysicsShape;
			node.PhysicsBody = SCNPhysicsBody.CreateBody (SCNPhysicsBodyType.Dynamic, coconutPhysicsShape);
			node.PhysicsBody.Restitution = 0.9f;
			node.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
			node.PhysicsBody.CategoryBitMask = GameCollisionCategory.Coconut;

			node.Transform = worldMtx;
			GameSimulation.Sim.RootNode.AddChildNode (node);
			GameSimulation.Sim.GameLevel.Coconuts.Add (node);
			node.PhysicsBody.ApplyForce (new SCNVector3 (-200, 500, 300), true);
			hasCoconut = false;
			isIdle = true;
		}
Ejemplo n.º 41
0
        void SetupGetCoconutAnimation()
        {
            SCNAnimationEventHandler pickupEventBlock = (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                if (coconutInHand != null)
                {
                    coconutInHand.RemoveFromParentNode();
                }

                coconutInHand = Coconut.CoconutProtoObject;
                rightHand.AddChildNode(coconutInHand);
                hasCoconut = true;
            };

            CAAnimation getAnimation = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_get_coconut"), "monkey_get_coconut-1");

            if (getAnimation.AnimationEvents == null)
            {
                getAnimation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.4f, pickupEventBlock) }
            }
            ;

            getAnimation.RepeatCount = 1;
        }

        void SetupThrowAnimation()
        {
            CAAnimation throwAnimation = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_throw_coconut"), "monkey_throw_coconut-1");

            throwAnimation.Speed = 1.5f;

            if (throwAnimation.AnimationEvents == null || throwAnimation.AnimationEvents.Length == 0)
            {
                SCNAnimationEventHandler throwEventBlock = ThrowCoconut;

                throwAnimation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.35f, throwEventBlock) };
            }

            throwAnimation.RepeatCount = 0;
        }

        void ThrowCoconut(CAAnimation animation, NSObject animatedObject, bool playingBackward)
        {
            if (!hasCoconut)
            {
                return;
            }

            SCNMatrix4 worldMtx = coconutInHand.PresentationNode.WorldTransform;

            coconutInHand.RemoveFromParentNode();

            Coconut         node = Coconut.CoconutThrowProtoObject;
            SCNPhysicsShape coconutPhysicsShape = Coconut.CoconutPhysicsShape;

            node.PhysicsBody                  = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Dynamic, coconutPhysicsShape);
            node.PhysicsBody.Restitution      = 0.9f;
            node.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
            node.PhysicsBody.CategoryBitMask  = GameCollisionCategory.Coconut;

            node.Transform = worldMtx;
            GameSimulation.Sim.RootNode.AddChildNode(node);
            GameSimulation.Sim.GameLevel.Coconuts.Add(node);
            node.PhysicsBody.ApplyForce(new SCNVector3(-200, 500, 300), true);
            hasCoconut = false;
            isIdle     = true;
        }
    }
Ejemplo n.º 42
0
        public void UpdateCubes()
        {
            double elapsedTime = CAAnimation.CurrentMediaTime() - timeOfLastRenderedFrame;

            bigCube.Red = bigCube.Red + (bigCubeDirections.Red * deltas.Red * (float)elapsedTime);
            if (bigCube.Red < minimums.Red || bigCube.Red > maximums.Red)
            {
                bigCube.Red            = Math.Max(minimums.Red, Math.Min(maximums.Red, bigCube.Red));
                bigCubeDirections.Red *= -1;
            }

            bigCube.Green = bigCube.Green + (bigCubeDirections.Green * deltas.Green * (float)elapsedTime);
            if (bigCube.Green < minimums.Green || bigCube.Green > maximums.Green)
            {
                bigCube.Green            = Math.Max(minimums.Green, Math.Min(maximums.Green, bigCube.Green));
                bigCubeDirections.Green *= -1;
            }

            bigCube.Blue = bigCube.Blue + (bigCubeDirections.Blue * deltas.Blue * (float)elapsedTime);
            if (bigCube.Blue < minimums.Blue || bigCube.Blue > maximums.Blue)
            {
                bigCube.Blue            = Math.Max(minimums.Blue, Math.Min(maximums.Blue, bigCube.Blue));
                bigCubeDirections.Blue *= -1;
            }

            bigCube.XAxis = bigCube.XAxis + (bigCubeDirections.XAxis * deltas.XAxis * (float)elapsedTime);
            if (bigCube.XAxis < minimums.XAxis || bigCube.XAxis > maximums.XAxis)
            {
                bigCube.XAxis            = Math.Max(minimums.XAxis, Math.Min(maximums.XAxis, bigCube.XAxis));
                bigCubeDirections.XAxis *= -1;
            }

            bigCube.YAxis = bigCube.YAxis + (bigCubeDirections.YAxis * deltas.YAxis * (float)elapsedTime);
            if (bigCube.YAxis < minimums.YAxis || bigCube.YAxis > maximums.YAxis)
            {
                bigCube.YAxis            = Math.Max(minimums.YAxis, Math.Min(maximums.YAxis, bigCube.YAxis));
                bigCubeDirections.YAxis *= -1;
            }

            bigCube.ZAxis = bigCube.ZAxis + (bigCubeDirections.ZAxis * deltas.ZAxis * (float)elapsedTime);
            if (bigCube.ZAxis < minimums.ZAxis || bigCube.Red > maximums.ZAxis)
            {
                bigCube.ZAxis            = Math.Max(minimums.ZAxis, Math.Min(maximums.ZAxis, bigCube.ZAxis));
                bigCubeDirections.ZAxis *= -1;
            }

            bigCube.Speed = bigCube.Speed + (bigCubeDirections.Speed * deltas.Speed * (float)elapsedTime);
            if (bigCube.Speed < minimums.Speed || bigCube.Speed > maximums.Speed)
            {
                bigCube.Speed            = Math.Max(minimums.Speed, Math.Min(maximums.Speed, bigCube.Speed));
                bigCubeDirections.Speed *= -1;
            }

            bigCube.RotationRadians = UpdatedRotationRadians(bigCube.RotationRadians, bigCube.Speed, elapsedTime);

            for (int i = 0; i < NumLittleCubes; i++)
            {
                littleCube [i].RotationRadians = UpdatedRotationRadians(littleCube [i].RotationRadians, littleCube [i].Speed, elapsedTime);
            }

            timeOfLastRenderedFrame = CAAnimation.CurrentMediaTime();
        }
Ejemplo n.º 43
0
		void AttachFadeoutAnimation (CALayer progress, CAAnimation animation, Func<bool> fadeoutVerifier)
		{
			animation.AnimationStopped += (sender, e) => {
				if (!fadeoutVerifier ()) {
					return;
				}

				if (!e.Finished) {
					return;
				}

				CABasicAnimation fadeout = CABasicAnimation.FromKeyPath ("opacity");
				fadeout.From = NSNumber.FromDouble (1);
				fadeout.To = NSNumber.FromDouble (0);
				fadeout.Duration = 0.5;
				fadeout.FillMode = CAFillMode.Forwards;
				fadeout.RemovedOnCompletion = false;
				fadeout.AnimationStopped += (sender2, e2) => {
					if (!e2.Finished)
						return;

					// Reset all the properties.
					inProgress = false;

					progress.Hidden = true;

					progress.Opacity = 1;
					progress.Frame = new CGRect (0, 0, 0, barHeight);
					progress.RemoveAllAnimations ();
					oldFraction = 0.0;

					progress.Hidden = false;
				};
				progress.Name = ProgressLayerFadingId;
				progress.AddAnimation (fadeout, "opacity");
			};
			progress.AddAnimation (animation, growthAnimationKey);
		}
 public override void AnimationStopped(CAAnimation anim, bool finished)
 {
     if (CompletionCallback != null)
     {
         CompletionCallback();
     }
 }
Ejemplo n.º 45
0
        void SetupHangAnimation()
        {
            CAAnimation hang = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_tree_hang"), "monkey_tree_hang-1");

            hang.RepeatCount = float.MaxValue;
        }
Ejemplo n.º 46
0
 private static CAAnimation ShimmerSlideFinish(CAAnimation a)
 {
     CAAnimation anim = (CAAnimation)a.Copy();
     anim.RepeatCount = 0;
     return anim;
 }
Ejemplo n.º 47
0
        // Takes a string an creates a node hierarchy where each letter is an independent geometry that is animated
        private SCNNode SplittedStylizedText(string message)
        {
            var textNode      = SCNNode.Create();
            var frontMaterial = TextFrontMaterial();
            var border        = TextSideAndChamferMaterial();

            // Current x position of the next letter to add
            var positionX = 0.0f;

            // For each letter
            for (var i = 0; i < message.Length; i++)
            {
                var letterNode   = SCNNode.Create();
                var letterString = message.Substring(i, 1);
                var text         = SCNText.Create(letterString, 50.0f);
                text.Font = NSFont.FromFontName("Avenir Next Heavy", 288);

                text.ChamferRadius  = 3.0f;
                text.ChamferProfile = TextChamferProfile();

                // use a different material for the "heart" character
                var finalFrontMaterial = frontMaterial;
                if (i == 1)
                {
                    finalFrontMaterial = (SCNMaterial)finalFrontMaterial.Copy();
                    finalFrontMaterial.Diffuse.Contents    = NSColor.Red;
                    finalFrontMaterial.Reflective.Contents = NSColor.Black;
                    letterNode.Scale = new SCNVector3(1.1f, 1.1f, 1.0f);
                }

                text.Materials = new SCNMaterial[] { finalFrontMaterial, finalFrontMaterial, border, border, border };

                letterNode.Geometry = text;
                textNode.AddChildNode(letterNode);

                // measure the letter we just added to update the position
                SCNVector3 min, max;
                max = new SCNVector3(0, 0, 0);
                min = new SCNVector3(0, 0, 0);
                if (letterNode.GetBoundingBox(ref min, ref max))
                {
                    letterNode.Position = new SCNVector3(positionX - min.X + (max.X + min.X) * 0.5f, -min.Y, 0);
                    positionX          += (float)max.X;
                }
                else
                {
                    // if we have no bounding box, it is probably because of the "space" character. In that case, move to the right a little bit.
                    positionX += 50.0f;
                }

                // Place the pivot at the center of the letter so that the rotation animation looks good
                letterNode.Pivot = SCNMatrix4.CreateTranslation((max.X + min.X) * 0.5f, 0, 0);

                // Animate the letter
                var animation = CAKeyFrameAnimation.GetFromKeyPath("rotation");
                animation.Duration = 4.0f;
                animation.KeyTimes = new NSNumber[] { 0.0f, 0.3f, 1.0f };
                animation.Values   = new NSObject[] {
                    NSValue.FromVector(new SCNVector4(0, 1, 0, 0)),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2)))
                };

                var timingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimingFunctions = new CAMediaTimingFunction[] { timingFunction, timingFunction, timingFunction };
                animation.RepeatCount     = float.MaxValue;
                animation.BeginTime       = CAAnimation.CurrentMediaTime() + 1.0 + i * 0.2;            // desynchronize animations
                letterNode.AddAnimation(animation, new NSString("letterNodeAnimation"));
            }

            return(textNode);
        }
 public override void AnimationStarted(CAAnimation anim)
 {
     //throw new NotImplementedException();
 }