# Sprites

> Every sprite is drawn as a textured quad; one with no texture is drawn as a plain coloured quad.

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

Every sprite is drawn as a textured quad. The logo loads `gammix.png` with `useLoadTexture` and slides across the screen; the semi-transparent box has no texture and is drawn as a plain quad in its tint colour.

## Code

`index.ts`:

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

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

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

`components/moving_logo.ts`:

```ts
import { createSprite, useLoadTexture, useUpdate } from 'nacatamalon';
import { WIDTH, LOGO } from '../settings';

export const MovingLogo = () => {
    // The handle is available immediately; its picture appears when loading finishes.
    const texture = useLoadTexture({
        src: LOGO.src
    });

    const logo = createSprite({
        texture,
        width: LOGO.size,
        height: LOGO.size,
        transform: {
            x: 64,
            y: 64
        }
    });

    useUpdate((delta) => {
        logo.transform.x += LOGO.speed * delta;

        if (logo.transform.x > WIDTH + LOGO.size / 2) {
            logo.transform.x = -LOGO.size / 2;
        }
    });
};
```

`scenes/demo.ts`:

```ts
import { createScene, createSprite, useSpawn } from 'nacatamalon';
import { MovingLogo } from '../components/moving_logo';

export const Game = () => {
    useSpawn(MovingLogo)();

    // With no texture a sprite is a flat rectangle; the tint's alpha makes it translucent.
    createSprite({
        width: 32,
        height: 32,
        tint: {
            r: 1,
            g: 1,
            b: 1,
            a: 0.5
        },
        transform: {
            x: 216,
            y: 236
        }
    });

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;

export const LOGO = {
    src: '/example-assets/assets/gammix.png',
    size: 64,
    speed: 80
};
```
