---
url: /concepts/animation.md
---
# Animation
CanvasEngine provides powerful tools for creating animations. At the core of the animation system are `animatedSignal` and `animatedSequence`.
## `animatedSignal`
An `animatedSignal` is a special type of signal whose changes can be animated over time. It's built on top of the reactive system and integrates with `popmotion` for the animation logic.
### Creation
You create an `animatedSignal` by providing an initial value and optional animation options:
```html
```
### Updating Value
You can update the value of an `animatedSignal` in two ways:
1. **`set(newValue, options?)`**: This method animates the signal from its current value to `newValue`. It returns a Promise that resolves when the animation is complete. You can optionally provide animation options specific to this transition.
```html
```
2. **`update(updaterFn)`**: This method takes a function that receives the current value and should return the new value. The transition to the new value will be animated using the default or previously set animation options for the signal.
```html
```
### Accessing Value
To get the current value of an `animatedSignal`, you call it as a function:
```html
```
### Animation State
Each `animatedSignal` has an `animatedState` property. This is a `WritableSignal` that holds an object with the following properties:
* `current`: The current value of the signal during an animation.
* `start`: The value at the beginning of the current or last animation.
* `end`: The target value of the current or last animation.
You can subscribe to this state to react to changes during an animation:
```html
```
### Example
```html
```
## `animatedSequence`
The `animatedSequence` function allows you to orchestrate multiple animations, running them sequentially or in parallel. This is particularly useful for creating complex animation timelines.
### How it Works
`animatedSequence` takes an array as its argument. Each element in this array can be either:
1. A function that returns a `Promise` (typically an `animatedSignal.set()` call). These functions are executed one after another (sequentially).
2. An array of such promise-returning functions. All functions within this inner array are executed simultaneously (in parallel). The sequence will only proceed to the next step once all promises in the parallel block have resolved.
### Usage
```html
```
### Key Features:
* **Sequential Execution**: Animations in the main array are performed one by one.
* **Parallel Execution**: Animations within a nested array are performed concurrently.
* **Promise-based**: It leverages Promises to manage the timing and completion of animations. The `animatedSequence` function itself returns a Promise that resolves when the entire sequence is finished.
This structure provides a flexible way to define intricate animation chains.
---
---
url: /presets/bar.md
---
# Bar
## Usage
```html
```
## Props
| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| backgroundColor | string | No | '#333333' | Background color of the bar |
| foregroundColor | string | No | '#ffffff' | Color of the progress bar |
| value | number | Yes | - | Current value of the progress bar |
| maxValue | number | Yes | - | Maximum value of the progress bar |
| width | number | Yes | - | Width of the bar in pixels |
| height | number | Yes | - | Height of the bar in pixels |
---
---
url: /components/button.md
---
# Button
The Button component provides an interactive button with visual feedback for different states (normal, hover, pressed, disabled). It supports both sprite-based and graphics-based rendering approaches.
## Basic Usage
```html