private protected void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            if (!Pressed)
            {
                return;
            }
            // start inert scrolling
            if (Scroller != null)
            {
                Scroller.OnTouchesEnded(touches, touchEvent);
            }
            switch (touches.Count)
            {
            case 1:
            {
            }
            break;

            default:
                break;
            }
            Pressed = false;
        }
        private protected void OnTouchesMovedMoveAndZoom(List <CCTouch> touches, CCEvent touchEvent)
        {
            if (!Pressed)
            {
                return;
            }
            //Console.WriteLine("touches.Count: " + touches.Count);
            //Console.WriteLine("TouchCount: " + TouchCount);
            switch (touches.Count)
            {
            case 1:
            {
                if (TouchCount == 2)
                {
                    goto zoom;
                }
                // move the camera
                if (Scroller != null)
                {
                    Scroller.OnTouchesMoved(touches, touchEvent);
                }
            }
            break;

            case 2:
zoom:
                {
                    // check for zoom
                    float   zoomFactor = 1f;
                    CCTouch touch1     = touches[0];
                    CCTouch touch2     = null;
                    CCPoint touch1Loc  = touch1.Location;
                    CCPoint touch2Loc  = CCPoint.Zero;
                    if (touches.Count == 2)
                    {
                        touch2     = touches[1];
                        touch2Loc  = touch2.Location;
                        zoomFactor = MyTouchExtensions.GetZoom(touch1, touch2);
                    }
                    else
                    {
                        foreach (var touch in ActiveTouches.Keys)
                        {
                            if (touch != touch1)
                            {
                                touch2Loc = ActiveTouches[touch];
                            }
                        }
                        zoomFactor = MyTouchExtensions.GetZoomOneTouchMoving(touch1, touch2Loc);
                    }
                    if (!float.IsNaN(zoomFactor))
                    {
                        var oldCameraSize = new CCSize(CameraSize.Width, CameraSize.Height);
                        CameraSize = new CCSize(oldCameraSize.Width * zoomFactor, oldCameraSize.Height * zoomFactor);
                        float   dw          = CameraSize.Width - oldCameraSize.Width;
                        float   dh          = CameraSize.Height - oldCameraSize.Height;
                        CCPoint touchCenter = new CCPoint((touch1Loc.X + touch2Loc.X) / 2, (touch1Loc.Y + touch2Loc.Y) / 2);
                        float   relativeX   = (touchCenter.X - CameraPosition.X) / oldCameraSize.Width;
                        float   relativeY   = (touchCenter.Y - CameraPosition.Y) / oldCameraSize.Height;
                        CameraPosition = new CCPoint(CameraPosition.X - dw * relativeX, CameraPosition.Y - dh * relativeY);
                        UpdateCamera();
                    }
                }
                break;

            default:
                break;
            }
        }
Exemple #3
0
 private protected override void OnTouchesEndedUI(List <CCTouch> touches, CCEvent touchEvent)
 {
     // start inert scrolling
     Scroller.OnTouchesEnded(touches, touchEvent);
 }
Exemple #4
0
 public override void Update(float dt)
 {
     base.Update(dt);
     // scroll on using inertia
     Scroller.Update(dt);
 }
Exemple #5
0
 private protected override void OnTouchesBeganUI(List <CCTouch> touches, CCEvent touchEvent)
 {
     // stop all scrolling
     Scroller.OnTouchesBegan(touches, touchEvent);
 }