private void OnTouchBegin(EventContext context)
    {
        if (touchId == -1)        //First touch
        {
            InputEvent evt = (InputEvent)context.data;
            touchId = evt.touchId;

            if (_tweener != null)
            {
                _tweener.Kill();
                _tweener = null;
            }

            Vector2 pt = GRoot.inst.GlobalToLocal(new Vector2(evt.x, evt.y));
            float   bx = pt.x;
            float   by = pt.y;
            _button.selected = true;

            if (bx < 0)
            {
                bx = 0;
            }
            else if (bx > _touchArea.width)
            {
                bx = _touchArea.width;
            }

            if (by > GRoot.inst.height)
            {
                by = GRoot.inst.height;
            }
            else if (by < _touchArea.y)
            {
                by = _touchArea.y;
            }

            _lastStageX  = bx;
            _lastStageY  = by;
            _startStageX = bx;
            _startStageY = by;

            _center.visible = true;
            _center.SetPosition(bx - _center.width / 2, by - _center.height / 2);
            _button.SetPosition(bx - _button.width / 2, by - _button.height / 2);

            float deltaX  = bx - _InitX;
            float deltaY  = by - _InitY;
            float degrees = (float)Math.Atan2(deltaY, deltaX) * 180 / (float)Math.PI;
            _thumb.rotation = degrees + 90;

            context.CaptureTouch();
        }
    }
Example #2
0
        public DemoScene()
        {
            UIPackage.AddPackage("UI/MainMenu");

            //add a closebutton to scene
            GObject closeButton = UIPackage.CreateObject("MainMenu", "CloseButton");

            closeButton.SetPosition(GRoot.inst.width - closeButton.width - 10, GRoot.inst.height - closeButton.height - 10);
            closeButton.AddRelation(GRoot.inst, RelationType.Right_Right);
            closeButton.AddRelation(GRoot.inst, RelationType.Bottom_Bottom);
            closeButton.sortingOrder = 100000;
            closeButton.onClick.Add(OnClose);

            GRoot.inst.AddChild(closeButton);
        }