# Auto size

> With no width or height, a sprite takes its texture’s natural size as soon as it loads.

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

Leave out `width` and `height` and the sprite takes its texture's natural pixel size (here a 167×167 illustration), resolved by the renderer as soon as the texture finishes loading. The sprite on the right forces 64×64 from the same image, for comparison.

## 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: '#11151f'
});

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

`components/card.ts`:

```ts
import { createSprite } from 'nacatamalon';
import type { TTexture } from 'nacatamalon';
import { HEIGHT } from '../settings';

type TCardProps = {
    texture: TTexture;
    x: number;
    size?: number;
};

export const Card = ({ texture, x, size }: TCardProps) => {
    // Undefined dimensions keep automatic sizing; an explicit size stretches the whole picture.
    createSprite({
        texture,
        width: size,
        height: size,
        transform: {
            x,
            y: HEIGHT / 2
        }
    });
};
```

`scenes/demo.ts`:

```ts
import { createScene, useLoadTexture, useSpawn } from 'nacatamalon';
import { Card } from '../components/card';
import { CARD_SRC, EXPLICIT_SIZE } from '../settings';

export const Game = () => {
    const texture = useLoadTexture({
        src: CARD_SRC
    });

    const spawnCard = useSpawn(Card);

    spawnCard({
        texture,
        x: 130
    });
    spawnCard({
        texture,
        x: 370,
        size: EXPLICIT_SIZE
    });

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;
export const CARD_SRC = '/example-assets/assets/tcg/Illustrations/Character1.png';
export const EXPLICIT_SIZE = 64;
```
