示例#1
0
        // Handler for the ManipulationDelta event.
        // ManipulationDelta data is loaded into the
        // translations transforms and applied to the
        // upper touch rectangle and lower car images.
        void TouchRectangle_ManipulationDelta(object sender,
                                              ManipulationDeltaRoutedEventArgs e)
        {
            // TO-DO: Need to do more tests with inertia on all platforms.
            if (e.IsInertial != true)
            {
                // Move the upper touch rectangle along the x-axis.
                dragUpperTranslation.X += e.Delta.Translation.X;

                if (dragUpperTranslation.X >= 0 && dragUpperTranslation.X < (MainRoot.ActualWidth * 0.65))
                {
                    //Making sure the SketchCar is not bouncing and rotating wheels under this threshold.
                    CarStoryboard.Stop();

                    // Making sure the scene animation is paused at the same time if it was already started.
                    if (isAnimationStarted)
                    {
                        SceneStoryboard.Pause();
                    }

                    // Move the lower cars along the x-axis and keeping the same upper y-axis.
                    dragLowerTranslation.X = dragUpperTranslation.X;
                    dragLowerTranslation.Y = dragUpperTranslation.Y;
                }
                else if (dragUpperTranslation.X >= (MainRoot.ActualWidth * 0.65))
                {
                    // Keep the upper rectangle at the same position as the lower rectangle.
                    dragUpperTranslation.X = dragLowerTranslation.X;
                    dragUpperTranslation.Y = dragLowerTranslation.Y;

                    //Starting the SketchCar bouncing and rotating wheels animations above the threshold.
                    CarStoryboard.Begin();

                    // Making sure the scene animation begin for the first time or resume if paused.
                    if (isAnimationStarted)
                    {
                        SceneStoryboard.Resume();
                    }
                    else
                    {
                        SceneStoryboard.Begin();
                        isAnimationStarted = true;
                    }
                }
                else
                {
                    // Keep the upper rectangle at the same position as the lower rectangle.
                    dragUpperTranslation.X = dragLowerTranslation.X;
                    dragUpperTranslation.Y = dragLowerTranslation.Y;

                    // Making sure the scene animation is paused at the same time if it was already started.
                    if (isAnimationStarted)
                    {
                        SceneStoryboard.Pause();
                    }
                }
            }
        }
示例#2
0
        private async void HingeAngleSensor_ReadingChanged(HingeAngleSensor sender, HingeAngleSensorReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var angleValue = args.Reading.AngleInDegrees;

                AngleValue.Content = "Angle value: " + angleValue.ToString();

                //Making sure we are not moving again the cars if we are keeping the same angle
                if (angleValue != previousAngle)
                {
                    previousAngle = angleValue;

                    // When the dual-screen device is half-opened
                    if (angleValue == 180)
                    {
                        //Making sure the SketchCar is not bouncing and rotating wheels.
                        CarStoryboard.Stop();

                        // Making sure the scene animation is paused at the same time if it was already started.
                        if (isSceneAnimationStarted)
                        {
                            SceneStoryboard.Pause();
                        }

                        // Move the lower cars along the x-axis in the middle of the screen and keeping the same upper y-axis.
                        dragLowerTranslation.X = (MainRoot.ActualWidth / 2) - (MainRoot.ActualWidth *leftSideThresholdRatio) - 100;
                        dragLowerTranslation.Y = dragUpperTranslation.Y;

                        // Keep the upper rectangle at the same position as the lower rectangle.
                        dragUpperTranslation.X = dragLowerTranslation.X;
                    }
                    // When the dual-screen device is fully opened, meaning that both screens are facing aware from each other.
                    else if (angleValue == 360)
                    {
                        // Move the lower cars along the x-axis on the right side of the screen and keeping the same upper y-axis.
                        dragLowerTranslation.X = MainRoot.ActualWidth *rightSideThresholdRatio;
                        dragLowerTranslation.Y = dragUpperTranslation.Y;

                        // Keep the upper rectangle at the same position as the lower rectangle.
                        dragUpperTranslation.X = dragLowerTranslation.X;
                        dragUpperTranslation.Y = dragLowerTranslation.Y;

                        // Making sure the SketchCar bouncing and rotating wheels animations begin for
                        // the first time or correctly being stopped and begin again if already started.
                        if (isCarAnimationStarted)
                        {
                            CarStoryboard.Stop();
                            CarStoryboard.Begin();
                        }
                        else
                        {
                            CarStoryboard.Begin();
                            isCarAnimationStarted = true;
                        }

                        // Making sure the scene animation begin for the first time or resume if paused.
                        if (isSceneAnimationStarted)
                        {
                            SceneStoryboard.Resume();
                        }
                        else
                        {
                            SceneStoryboard.Begin();
                            isSceneAnimationStarted = true;
                        }
                    }
                }
            });
        }