better touch controls!

This commit is contained in:
Ellpeck 2020-06-15 16:49:13 +02:00
parent b73d9fe1ef
commit b4a75ff58e

View file

@ -79,15 +79,12 @@ namespace TouchyTickets {
if (GameImpl.Instance.DrawMap && GameImpl.Instance.UiSystem.Controls.HandleTouch) { if (GameImpl.Instance.DrawMap && GameImpl.Instance.UiSystem.Controls.HandleTouch) {
var camera = GameImpl.Instance.Camera; var camera = GameImpl.Instance.Camera;
if (MlemGame.Input.GetGesture(GestureType.Pinch, out var pinch)) { if (MlemGame.Input.GetGesture(GestureType.Pinch, out var pinch)) {
var startDiff = pinch.Position2 - pinch.Position; // pinch zoom
var endDiff = pinch.Position2 + pinch.Delta2 - (pinch.Position + pinch.Delta); var center = (pinch.Position + pinch.Position2) / 2;
if (startDiff.LengthSquared() < endDiff.LengthSquared()) { var newDist = Vector2.Distance(pinch.Position + pinch.Delta, pinch.Position2 + pinch.Delta2);
// zooming in var oldDist = Vector2.Distance(pinch.Position, pinch.Position2);
camera.Zoom(pinch.Delta.Length() / camera.Scale); var newScale = newDist / oldDist * camera.Scale;
} else { camera.Zoom(newScale - camera.Scale, center);
// zooming out
camera.Zoom(-pinch.Delta.Length() / camera.Scale);
}
} else if (MlemGame.Input.GetGesture(GestureType.FreeDrag, out var drag)) { } else if (MlemGame.Input.GetGesture(GestureType.FreeDrag, out var drag)) {
if (this.draggingAttraction) { if (this.draggingAttraction) {
// move the current placing position // move the current placing position
@ -98,7 +95,7 @@ namespace TouchyTickets {
this.PlacingPosition = nextPos; this.PlacingPosition = nextPos;
} else { } else {
// move the camera // move the camera
camera.Position -= drag.Delta / camera.Scale; camera.Position -= drag.Delta / camera.ActualScale;
} }
} else if (this.PlacingAttraction != null) { } else if (this.PlacingAttraction != null) {
foreach (var touch in MlemGame.Input.TouchState) { foreach (var touch in MlemGame.Input.TouchState) {