# ui/uispinner (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/ui/uispinner/

Spinning loading indicator.

## UISpinner extends WorldNode

Spinning loading indicator.
- A standard spinner with several dots around a circle whose brightness rotates like a tail.
- Usage:
    const spinner = new UISpinner({ radius: 9, dotCount: 10 });
    someNode.addChild(spinner);
    spinner.setLocalPosition(Vector2.create(x, y));

Example: Spinning a spinner in the middle of the screen

```js
import { Engine, EngineConfiguration, UIScene, UISpinner, Color, Vector2 } from "./build/vanilla.js";

class SpinnerScene extends UIScene {
	create() {
		super.create();
		const spinner = new UISpinner({ radius: 16, dotCount: 12, dotRadius: 3, color: new Color(0.4, 0.7, 1, 1), rotationSpeed: 0.8 });
		spinner.setLocalPosition(Vector2.create(320, 180));
		spinner.setDotColor(new Color(1, 0.8, 0.3, 1));
		const root = this.getRoot();
		root.addChild(spinner);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new SpinnerScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
```

- `constructor(options = {})` (constructor, since 0.3.0): Constructor.
  - `options` object: { radius = 9, dotCount = 10, dotRadius = 2, color?, rotationSpeed = 1 }
- `tick(timeDelta)` (method, since 0.3.0): Update. (rotates the brightness tail)
  - `timeDelta` number: Time since the last frame. (Seconds)
- `calculateDotOpacity(dotIndex)` (method, since 0.4.0): Computes a dot's opacity. (the smaller the tail ratio, the dot order ratio minus the phase, the brighter)
  - With no dots (dotCount 0) the order ratio is taken as 0.
  - `dotIndex` number: Dot index. (from 0, starting at the right and going clockwise)
  - returns number: Opacity. (0.15 ~ 1, the head dot of the brightness tail is 1)
- `getDotColor()` (method, since 0.4.0): Returns the dot color.
  - returns Color: Dot color. (the original, not cloned)
- `getRotationSpeed()` (method, since 0.4.0): Returns the rotation speed. (turns per second)
  - returns number: Turns per second.
- `getDotNodes()` (method, since 0.4.0): Returns the dot node list.
  - returns WorldNode[]: Copy of the dot node list. (the dot nodes are the same)
- `setDotColor(dotColor)` (method, since 0.3.0): Sets the dot color.
  - `dotColor` Color | string: Dot color. (cloned and set on every dot's Paint)
- `setRotationSpeed(rotationSpeed)` (method, since 0.3.0): Sets the rotation speed. (turns per second)
  - `rotationSpeed` number: Turns per second. (negative turns backward)
