public override void _Input(InputEvent @event) { if (@event is InputEventMouseButton && PlayerController.Focus == null) { var emb = (InputEventMouseButton)@event; // leave these brackets for future keybinds { if (emb.ButtonIndex == (int)ButtonList.WheelUp && Zoom.Length() > min_zoom_distance) { Zoom = Zoom - new Vector2(smoothness, smoothness); } if (emb.ButtonIndex == (int)ButtonList.WheelDown && Zoom.Length() < max_zoom_distance) { Zoom = Zoom + new Vector2(smoothness, smoothness); } } } if (@event is InputEventScreenTouch) { var ev = (InputEventScreenTouch)@event; if (@event.IsPressed()) { events[ev.Index] = ev.Position; } else { events.Remove(ev.Index); } } if (@event is InputEventScreenDrag) { var drag = (InputEventScreenDrag)@event; MoveLocalX(-drag.Relative.x * drag_sensitivity); MoveLocalY(-drag.Relative.y * drag_sensitivity); events[drag.Index] = drag.Position; if (events.Count == 2) { var drag_distance = events[0].DistanceTo(events[1]); if (Mathf.Abs(drag_distance - last_drag_distance) > zoom_sensitivity) { var new_zoom = drag_distance < last_drag_distance ? 1 + zoom_speed : 1 - zoom_speed; new_zoom = Mathf.Clamp(Zoom.x * new_zoom, min_zoom_distance * mobile_zoom_offset_multiplier, max_zoom_distance * mobile_zoom_offset_multiplier); Zoom = Vector2.One * new_zoom; last_drag_distance = drag_distance; } } } }
// Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(float delta) { if (cameraTargetNode != null) { Vector2 targetPosition = cameraTargetNode.GlobalPosition; GlobalPosition = targetPosition; } if (Input.IsActionJustReleased("ZoomOut") && Zoom.Length() > 0.25f) { Zoom = Zoom * 0.9f; } if (Input.IsActionJustReleased("ZoomIn") && Zoom.Length() < 4f) { Zoom = Zoom * 1.1f; } }