예제 #1
0
        private void touchHandle(EventX e)
        {
            Vector2X p      = (Vector2X)e.data;
            float    stageX = p.x;
            float    stageY = p.y;

            switch (e.type)
            {
            case MouseEventX.MOUSE_DOWN:
                mx = mx0 = stageX;
                my = my0 = stageY;

                _stage = stage;

                _stage.addEventListener(MouseEventX.MOUSE_MOVE, touchMoveHandle);
                _stage.addEventListener(MouseEventX.MOUSE_UP, touchHandle);
                break;

            case MouseEventX.MOUSE_UP:

                _stage.removeEventListener(MouseEventX.MOUSE_MOVE, touchMoveHandle);
                _stage.removeEventListener(MouseEventX.MOUSE_UP, touchHandle);

                if (_isDragging)
                {
                    touchEnd(stageX - mx, stageY - my, stageX - mx0, stageY - my0);
                    if (hasEventListener(TouchEventX.TOUCH_END))
                    {
                        this.dispatchEvent(new TouchEventX(TouchEventX.TOUCH_END, stageX - mx, stageY - my, stageX - mx0, stageY - my0));
                    }
                    _isDragging = false;
                    CallLater.Add(touchEndHandle);
                }

                break;
            }
        }
예제 #2
0
        private void touchMoveHandle(EventX e)
        {
            Vector2X p      = (Vector2X)e.data;
            float    stageX = p.x;
            float    stageY = p.y;

            float dx = stageX - mx0;
            float dy = stageY - my0;

            if (!_isDragging)
            {
                if (Math.Abs(dx) < draggingDistanceX || Math.Abs(dy) < draggingDistanceY || (dx * dx + dy * dy) < MIN_DISTANCE_SQ)
                {
                    return;
                }
                _isDragging     = true;
                _draggingTarget = this;
                CallLater.Remove(touchEndHandle);

                touchStart(dx, dy);//这里面可能会有需求再变为不可拖;

                if (hasEventListener(TouchEventX.TOUCH_START))
                {
                    this.dispatchEvent(new TouchEventX(TouchEventX.TOUCH_START, 0, 0, dx, dy));
                }
            }

            touchMoving(stageX - mx, stageY - my, dx, dy);
            if (hasEventListener(TouchEventX.TOUCH_START))
            {
                this.dispatchEvent(new TouchEventX(TouchEventX.TOUCH_START, stageX - mx, stageY - my, dx, dy));
            }

            mx = stageX;
            my = stageY;
        }