Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions docs/fetchAvailableSpriteStyles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: fetchAvailableSpriteStyles
description: A function to retrieve available sprite styles for character generation.
---

# fetchAvailableSpriteStyles

## Introduction

The `fetchAvailableSpriteStyles` function is a part of the sprite generation module. It allows developers to retrieve a list of available sprite styles that can be used when generating character sprites. This function is useful for providing options to users or for dynamically adjusting sprite generation parameters in your application.

## Usage

To use the `fetchAvailableSpriteStyles` function, import it from the sprite module and call it as an asynchronous function.

```javascript
import { fetchAvailableSpriteStyles } from './path/to/sprite/module';

async function getStyles() {
const styles = await fetchAvailableSpriteStyles();
console.log(styles);
}
```

## Function Signature

```javascript
async function fetchAvailableSpriteStyles(): Promise<string[]>
```

## Return Value

The function returns a Promise that resolves to an array of strings. Each string represents an available sprite style.

## Example

Here's a practical example of how to use `fetchAvailableSpriteStyles` in your application:

```javascript
import { fetchAvailableSpriteStyles, generateCharacterSpritesheet } from './path/to/sprite/module';

async function createCharacterWithRandomStyle(description) {
try {
const availableStyles = await fetchAvailableSpriteStyles();
const randomStyle = availableStyles[Math.floor(Math.random() * availableStyles.length)];

const spritesheet = await generateCharacterSpritesheet(description, {
style: randomStyle
});

console.log(`Generated character with style: ${randomStyle}`);
return spritesheet;
} catch (error) {
console.error('Error generating character:', error);
}
}

// Usage
createCharacterWithRandomStyle('A brave knight with shining armor');
```

## Available Styles

The current implementation returns the following styles:

- pixel-art
- vector
- 3d
- hand-drawn
- anime

Please note that the available styles may be updated in future versions of the module.

## Notes and Considerations

- The function is asynchronous and returns a Promise. Always use `await` or `.then()` when calling it.
- The list of available styles is hardcoded in the current implementation. Future versions may fetch this data from an external source or configuration file.
- If you need to support a specific style, it's recommended to check if it's included in the returned array before using it in sprite generation.

## Related Functions

- `generateCharacterSpritesheet`: Uses the styles from `fetchAvailableSpriteStyles` to generate character spritesheets.
- `fetchAvailableAnimationStates`: Retrieves available animation states for sprite generation.

## Next Steps

Now that you know how to fetch available sprite styles, you might want to explore:

- [How to generate a character spritesheet](./generateCharacterSpritesheet.md)
- [Customizing sprite generation options](./customizingSpriteGeneration.md)
- [Working with different sprite styles](./workingWithSpriteStyles.md)
94 changes: 94 additions & 0 deletions docs/generateEnvironmentSprites.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: Generate Environment Sprites
description: Learn how to use the generateEnvironmentSprites function to create custom environment sprites for your game.
---

# Generate Environment Sprites

## Introduction

The `generateEnvironmentSprites` function is a powerful tool for game developers to create custom environment sprites using AI-powered image generation. This tutorial will guide you through the process of using this function to generate a tileset for your game environment.

## Prerequisites

Before you begin, make sure you have:

- Node.js installed on your machine
- The `spriteAI` module installed in your project
- An OpenAI API key (the function uses DALL-E 3 for image generation)

## Getting Started

Let's create a set of environment sprites for a fantasy forest setting.

### Step 1: Import the function

First, import the `generateEnvironmentSprites` function from the `spriteAI` module:

```javascript
import { generateEnvironmentSprites } from './path/to/spriteAI';
```

### Step 2: Set up the function call

Now, let's call the function with a description of the environment we want to create:

```javascript
const description = "fantasy forest";
const options = {
elements: 6,
size: '1024x1024',
style: 'pixel-art',
padding: 2,
theme: 'fantasy',
save: true
};

generateEnvironmentSprites(description, options)
.then(result => console.log(result))
.catch(error => console.error(error));
```

### Step 3: Run the code

Execute your script. The function will generate the environment sprites and save them to your project's `assets` folder.

## Understanding the Output

The `generateEnvironmentSprites` function returns an object with the following properties:

- `original`: URL of the original AI-generated image
- `tileset`: Base64-encoded string of the processed tileset image
- `metadata`: Object containing information about the generated tileset

Here's an example of what the metadata might look like:

```javascript
{
elements: 6,
theme: 'fantasy',
dimensions: { width: '1024', height: '1024' },
tileData: { rows: 3, columns: 2, totalTiles: 6 }
}
```

## Customizing Your Sprites

You can customize the generated sprites by adjusting the options passed to the function:

- `elements`: Number of distinct environment pieces to generate (default: 4)
- `size`: Size of the generated image (default: '1024x1024')
- `style`: Art style of the sprites (default: 'pixel-art')
- `padding`: Padding between tiles (default: 1)
- `theme`: Theme of the environment (default: 'fantasy')
- `save`: Whether to save the generated image to disk (default: false)

## Next Steps

Now that you've generated your environment sprites, you might want to:

- Learn how to integrate these sprites into your game engine
- Explore generating character sprites with the `generateCharacterSpritesheet` function
- Understand how to manipulate and optimize the generated images for better performance

Check out our other How-To Guides and Reference docs for more information on working with AI-generated game assets!
115 changes: 115 additions & 0 deletions docs/generateItemSprites.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
title: Generate Item Sprites
description: Learn how to generate item sprites for your game using AI-powered image generation.
---

# Generate Item Sprites

## Introduction

The `generateItemSprites` function is a powerful tool that allows you to create item sprites for your game using AI-powered image generation. This tutorial will guide you through the process of using this function to generate custom item sprites based on your descriptions.

## Prerequisites

- Node.js installed on your machine
- Access to the `spriteAI` module
- An OpenAI API key (for DALL-E 3 image generation)

## Getting Started

First, let's import the necessary function from the `spriteAI` module:

```javascript
import { generateItemSprites } from './path/to/spriteAI';
```

## Generating Item Sprites

To generate item sprites, you'll need to provide a description and some optional parameters. Here's a basic example:

```javascript
const description = "medieval fantasy weapons";
const options = {
itemCount: 4,
size: '1024x1024',
style: 'pixel-art',
itemType: 'equipment'
};

const result = await generateItemSprites(description, options);
```

Let's break down the parameters:

- `description`: A string describing the items you want to generate.
- `options`: An object containing various customization options:
- `itemCount`: Number of items to generate (default: 4)
- `size`: Size of the generated image (default: '1024x1024')
- `style`: Visual style of the items (default: 'pixel-art')
- `itemType`: Type of items to generate (default: 'equipment')
- `padding`: Padding between items (default: 1)
- `background`: Background color (default: 'white')
- `save`: Whether to save the generated image to disk (default: false)

## Understanding the Result

The function returns an object with the following properties:

```javascript
{
original: 'https://url-to-original-image.com',
itemSheet: 'data:image/png;base64,base64EncodedImageData',
metadata: {
itemCount: 4,
itemType: 'equipment',
dimensions: {
width: '1024',
height: '1024'
},
itemData: {
rows: 2,
columns: 2,
totalItems: 4
}
}
}
```

- `original`: URL of the original generated image.
- `itemSheet`: Base64-encoded data URL of the processed item sheet.
- `metadata`: Object containing information about the generated items.

## Customizing Your Sprites

You can customize your item sprites by adjusting the options. For example, to generate 8 sci-fi gadgets in a vector style:

```javascript
const result = await generateItemSprites("futuristic sci-fi gadgets", {
itemCount: 8,
style: 'vector',
itemType: 'technology',
background: 'transparent'
});
```

## Saving Generated Sprites

To save the generated sprites to disk, set the `save` option to `true`:

```javascript
const result = await generateItemSprites("magical potions", {
save: true
});
```

The sprites will be saved in the `assets` folder with a filename based on the description.

## Next Steps

Now that you've learned how to generate item sprites, you might want to explore:

- [How to integrate generated sprites into your game engine](link-to-integration-guide)
- [Customizing sprite generation with advanced DALL-E 3 prompts](link-to-advanced-prompts-guide)
- [Managing and organizing your generated game assets](link-to-asset-management-guide)

By mastering the `generateItemSprites` function, you'll be able to quickly create diverse and unique items for your game, saving time and enhancing your game's visual appeal.
Loading