# Watch a load

> useWatch over an asset: the texture announces itself when it lands, so the placeholder is swapped by a callback that runs twice.

Example `watch-load`, running at https://nacatamalon.com/en/examples/watch-load. The whole catalogue: https://nacatamalon.com/llms/examples.md.

`useWatch` is not only for `useData`: an asset announces itself when it lands, so the placeholder is swapped for the picture by a callback that runs exactly twice instead of a check made sixty times a second. Reload the page to see the loading frame, which is held back on purpose here because the file is already in memory.

What cannot be watched is anything the game moves by hand, a position above all: nothing announces those, so `useWatch` refuses them when the scene starts rather than going quiet.

## Code

`index.ts`:

```ts
import { createGame } from 'nacatamalon';
import { WIDTH, HEIGHT } from './settings';
import { Level } from './scenes/demo';

const game = createGame('#app', {
    width: WIDTH,
    height: HEIGHT,
    background: '#14121c',
});

// Declare Scenes
game({
    Level
});
```

`components/preview.ts`:

```ts
import { createSprite, createText, useLoadBitmapFont, useLoadTexture, useWatch } from 'nacatamalon';
import * as Settings from '../settings';

export const Preview = () => {
    const font = useLoadBitmapFont(Settings.FONT);

    // An asset is watchable like state is: the engine says when it lands, so nothing here has to
    // ask every frame whether it has.
    const hero = useLoadTexture({
        src: '/example-assets/assets/gammix.png',
        key: 'gammix'
    });

    const sprite = createSprite({
        texture: hero,
        width: 96,
        height: 96,
        transform: {
            x: 170,
            y: 80
        }
    });

    const label = createText({
        text: '',
        font,
        style: {
            fontSize: 8
        },
        tint: '#8fa4c4',
        anchor: {
            x: 0.5,
            y: 0.5
        },
        transform: {
            x: 170,
            y: 150
        },
    });

    // A placeholder drawn from the very first frame, while the image is still on its way.
    const slot = createSprite({
        tint: '#2a2a3c',
        width: 96,
        height: 96,
        transform: {
            x: 170,
            y: 80
        },
    });

    // Runs once now, with the texture still loading, and once more when it lands. Two runs, no
    // polling: compare this with reading hero.status inside a useUpdate sixty times a second.
    useWatch(() => {
        const ready = hero.status === 'ready';

        sprite.visible = ready;
        slot.visible = !ready;
        label.text = ready ? 'READY ' + hero.width + 'x' + hero.height : 'LOADING…';
    }, [hero]);
};
```

`scenes/demo.ts`:

```ts
import { createScene, useSpawn } from 'nacatamalon';

import { Preview } from '../components/preview';

export const Level = () => {
    useSpawn(Preview)();

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 340;
export const HEIGHT = 180;
export const FONT = {
    json: '/example-assets/fonts/bitmaps/nacatamal-arcade/nacatamal-arcade.json',
    atlas: '/example-assets/fonts/bitmaps/nacatamal-arcade/nacatamal-arcade.png',
};
```
