コード例 #1
0
    public override void _Input(InputEvent @event)
    {
        // For testing only
        if (@event is InputEventKey keyEvent && keyEvent.Pressed)
        {
            if ((KeyList)keyEvent.Scancode == KeyList.T)
            {
                BouncingItem bounceTest = (BouncingItem)GD.Load <PackedScene>("res://BouncingItem.tscn").Instance();
                bounceTest.Position = Position;
                bounceTest.Initialise(new Vector2(15f, 0f), -60f);

                GetParent().AddChild(bounceTest);
            }
        }

        // 'action button' input
        if (@event is InputEventScreenTouch screenTouchEvent && screenTouchEvent.Pressed)
        {
            if (screenTouchEvent.Pressed && screenTouchEvent.Position.x > GetViewport().GetVisibleRect().Size.x / 2)
            {
                ActionButtonPressed(screenTouchEvent.Position);
            }
            else
            {
                ((Node2D)_joystick.GetParent()).GlobalPosition = screenTouchEvent.Position;
            }
        }
    }