---
title: Moving
---

# Moving/Dragging

You can use `BoxTransformer.move` to translate a box by some amount of pixels.

```dart title="Moving a box"
  final Box rect = Box.fromLTWH(50, 50, 100, 100);
  final MoveResult result = BoxTransformer.move(
    initialRect: rect,
    initialLocalPosition: Vector2.zero(),
    localPosition: Vector2.zero(),
  );

  result.position; // the new position of the box
```
`BoxTransformer.move` returns a `MoveResult` that contains information about the new position of the box.
`result.position` is a `Vector2` that defines the new position of the box.

## Limiting movements

You can limit the movements by providing `clampingRect` to `BoxTransformer.move` to limit the movements to a specific
area.

```dart title="Limiting movements"
  final Box rect = Box.fromLTWH(50, 50, 100, 100);
  final MoveResult result = BoxTransformer.move(
    initialRect: rect,
    initialLocalPosition: Vector2.zero(),
    localPosition: Vector2.zero(),
    clampingRect: Box.fromLTWH(0, 0, 1000, 1000),
  );

  result.position; // the new position of the box
```

## Moving a rotated box

`BoxTransformer.move` accepts `rotation` (radians) and `bindingStrategy` parameters. The solver computes the joint
feasible translation interval that keeps the rect inside the clamp under the active strategy and slides into it; if
the requested delta would push the box past the clamp, the result is clamped to the wall.

```dart title="Moving a rotated box"
  final MoveResult result = BoxTransformer.move(
    initialRect: Box.fromLTWH(50, 50, 100, 100, rotation: 0.4),
    initialLocalPosition: startCursor,
    localPosition: currentCursor,
    rotation: 0.4,
    bindingStrategy: BindingStrategy.boundingBox,
    clampingRect: clamp,
  );
```

See [Rotating](/rotating) and [Binding Strategies](/binding_strategies) for the rotation-specific semantics.
