# Pixel art

> The smooth option picks crisp or linear filtering: hard pixels when a retro sprite is scaled up.

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

Sprites are drawn with crisp filtering (nearest neighbour) by default, the retro default: the mushroom on the left, a 32×32 sprite scaled about 5.6 times, keeps its hard pixels.

The one on the right sets `smooth: true` on its own sprite and switches to linear filtering, which blurs. It is the general rule: one default for the whole game, and an exception per sprite.

## Code

`index.ts`:

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

const game = createGame('#app', {
    width: WIDTH,
    height: HEIGHT,
    // The game's answer for everything that does not choose. False is the retro default.
    smooth: false,
    background: '#10141d',
});

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

`components/comparison.ts`:

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

export const Comparison = () => {
    // A real 32 x 32 pixel-art mushroom, blown up about five and a half times so the difference
    // is impossible to miss.
    const texture = useLoadTexture(Settings.TEXTURE);

    // Left: nothing said, so it takes the game's smooth (false here, the retro default). Nearest
    // sampling, and a scaled-up pixel stays a square.
    createSprite({
        texture,
        width: Settings.SIZE,
        height: Settings.SIZE,
        transform: {
            x: 126,
            y: 170,
            rotation: 0,
            scaleX: 1,
            scaleY: 1
        },
    });

    // Right: the same texture at the same size, asking for the other one. Linear sampling blends
    // between texels, which is what turns pixel art to mush.
    createSprite({
        texture,
        width: Settings.SIZE,
        height: Settings.SIZE,
        smooth: true,
        transform: {
            x: 354,
            y: 170,
            rotation: 0,
            scaleX: 1,
            scaleY: 1
        },
    });
};
```

`scenes/demo.ts`:

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

import { Comparison } from '../components/comparison';

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

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;
export const SIZE = 180;
export const TEXTURE = {
    src: '/example-assets/assets/mushroom/Icon1.png',
    key: 'mushroom'
};
```
