# C#: Timing

Source: https://tweens.gd/csharp/api/timing/

Timing places a tween in time: how long each leg takes, when the first one starts, how often it repeats, and what the property shows before and after. [Loops & delays](https://tweens.gd/csharp/loops/) introduces it.

## Members

| Member | Type | Default | Meaning |
| --- | --- | --- | --- |
| [`Duration`](https://tweens.gd/csharp/api/timing/#duration) | `Duration` | `0` | Seconds per leg; zero completes on the first eligible update |
| [`Delay`](https://tweens.gd/csharp/api/timing/#delay) | `Duration` | `0` | Signed wait before the first leg; a negative delay pre-rolls |
| [`Offset`](https://tweens.gd/csharp/api/timing/#offset) | `Duration` | `0` | Start this far into the first forward leg, within `[0, Duration]`; the delay still comes first |
| [`Repeats`](https://tweens.gd/csharp/api/timing/#repeats) | `int` | `0` | Cycles after the first; `TweenOptions.Infinite` (-1) repeats until cancelled |
| [`PingPong`](https://tweens.gd/csharp/api/timing/#pingpong) | `bool` | `false` | Each cycle runs forward, then back |
| [`PingPongInterval`](https://tweens.gd/csharp/api/timing/#pingponginterval) | `Duration` | `0` | Wait at the far endpoint before returning |
| [`RepeatInterval`](https://tweens.gd/csharp/api/timing/#repeatinterval) | `Duration` | `0` | Wait between cycles, never after the last |
| [`Fill`](https://tweens.gd/csharp/api/timing/#fill) | `FillMode` | `RetainFinalValue` | What the property shows during the delay and after [natural completion](https://tweens.gd/csharp/api/timing/#fill-and-restoration) |

`FactorDuration`, `DeltaDuration`, `FactorDelay`, and `DeltaDelay` adjust `Duration` and `Delay` for each start; see [variations](https://tweens.gd/csharp/api/endpoints/#variations).

`Duration` is also a readonly record struct of `double` seconds. It converts implicitly from `float`, `double`, and `TimeSpan`, and back to `double`; `Seconds` reads the value. Its default is zero.

## Cycles

A cycle is one leg, or a forward leg, the ping-pong interval, and a return leg. Repeat intervals separate cycles:

```csharp
var bob = new Tweens.Position2DY
{
    By = -20,
    Duration = 0.5,
    PingPong = true,
    PingPongInterval = 0.2,
    RepeatInterval = 0.3,
    Repeats = 1,
};
```

Interactive preview: https://tweens.gd/csharp/api/timing/

A ping-pong tween ends at its starting endpoint, so that endpoint is its final value.

## Fill and restoration

| `FillMode` | During the initial delay | On natural completion |
| --- | --- | --- |
| `RetainFinalValue` | Leave the property alone | Keep the final value |
| `ApplyFromDuringDelay` | Apply `From` | Restore the captured initial value |
| `Both` | Apply `From` | Keep the final value |
| `None` | Leave the property alone | Restore the captured initial value |

-   `RetainFinalValue` is the default. `Both` suits staggered entrances: items still waiting show their `From` value.
-   Cancelling always keeps the latest value, whatever the fill mode.
-   Restoring a shader uniform also restores whether the material had an explicit override; see the [material reference](https://tweens.gd/csharp/nodes/materials/).

## Rules

-   Non-finite times, and negative durations, intervals, or offsets, throw when the tween starts.
-   An infinitely repeating cycle that takes zero time is rejected.
-   A long frame advances to the correct phase, even across several cycles, without losing time at boundaries. It doesn’t replay the callbacks of the cycles it skipped.
-   In a [Chain](https://tweens.gd/csharp/api/chains/#timeline), each entry’s delay counts from the end of the entry before it.
-   The clock that advances a tween, and whether time scale applies, is chosen when it starts; see [playback options](https://tweens.gd/csharp/api/start/#playback-options).
