/// <summary> /// This method is called when you release on the map. /// </summary> private void OnMapRelease() { // Is marked, that ended the interaction with the map. isInteract = false; // Calculates the average speed. rsX = speedX.Count > 0 ? speedX.Average() : 0; rsY = speedY.Count > 0 ? speedY.Average() : 0; if (waitZeroTouches && control.GetTouchCount() == 0) { waitZeroTouches = false; rsX = rsY = 0; } speedX.Clear(); speedY.Clear(); }
private void FixedUpdate() { if (isInteract && control.GetTouchCount() == 0) { isInteract = false; } // If there is interaction with the map. if (isInteract) { // Calculates speeds. double tx, ty; map.GetTilePosition(out tx, out ty, 20); double cSpeedX = tx - ptx; double cSpeedY = ty - pty; float cSpeedZ = map.floatZoom - pz; int halfMax = 1 << 19; int max = 1 << 20; if (cSpeedX > halfMax) { cSpeedX -= max; } else if (cSpeedX < -halfMax) { cSpeedX += max; } while (speedX.Count >= maxSamples) { speedX.RemoveAt(0); } while (speedY.Count >= maxSamples) { speedY.RemoveAt(0); } while (speedZ.Count >= maxSamples) { speedZ.RemoveAt(0); } speedX.Add(cSpeedX); speedY.Add(cSpeedY); speedZ.Add(cSpeedZ); ptx = tx; pty = ty; pz = map.floatZoom; } // If no interaction with the map. else if (rsX * rsX + rsY * rsY > 0.001 || rsZ > 0.001) { // Continue to move the map with the current speed. double tx, ty; map.GetTilePosition(out tx, out ty, 20); tx += rsX; ty += rsY; int max = 1 << 20; if (tx >= max) { tx -= max; } else if (tx < 0) { tx += max; } map.SetTilePosition(tx, ty, 20); //control.ZoomOnPoint(rsZ, lastScreenPoint); map.floatZoom += rsZ; // Reduces the current speed. rsX *= friction; rsY *= friction; rsZ *= friction; } }