diff --git a/docs/fetchAvailableSpriteStyles.md b/docs/fetchAvailableSpriteStyles.md new file mode 100644 index 00000000..0d071dc6 --- /dev/null +++ b/docs/fetchAvailableSpriteStyles.md @@ -0,0 +1,76 @@ +--- +title: Fetch Available Sprite Styles +description: Learn how to use the fetchAvailableSpriteStyles function to get a list of available sprite styles for character generation. +sidebar_position: 3 +--- + +# Fetch Available Sprite Styles + +## Introduction + +The `fetchAvailableSpriteStyles` function is a part of the SpriteAI module, which allows developers to retrieve a list of available sprite styles for character generation. This tutorial will guide you through using this function in your projects. + +## Prerequisites + +Before you begin, make sure you have: + +- Installed the SpriteAI module in your project +- Basic knowledge of JavaScript and asynchronous programming + +## How to Use fetchAvailableSpriteStyles + +Follow these steps to fetch the available sprite styles: + +1. Import the function from the SpriteAI module: + +```javascript +import { fetchAvailableSpriteStyles } from 'spriteAI'; +``` + +2. Call the function and handle the returned promise: + +```javascript +async function getStyles() { + try { + const styles = await fetchAvailableSpriteStyles(); + console.log('Available styles:', styles); + } catch (error) { + console.error('Error fetching styles:', error); + } +} + +getStyles(); +``` + +3. The function will return an array of available sprite styles. + +## Example Output + +The `fetchAvailableSpriteStyles` function returns an array of strings. Here's an example of what the output might look like: + +```javascript +['pixel-art', 'vector', '3d', 'hand-drawn', 'anime'] +``` + +## Use Cases + +You can use the `fetchAvailableSpriteStyles` function to: + +- Populate a dropdown menu for style selection in your character generation UI +- Validate user input when generating sprites +- Dynamically adjust your application based on available styles + +## Best Practices + +- Cache the results if you're calling this function frequently, as the available styles are unlikely to change often. +- Handle potential network errors or unexpected responses gracefully. +- Use the returned styles to ensure you're only offering valid options to your users. + +## Next Steps + +Now that you know how to fetch available sprite styles, you might want to explore: + +- [How to Generate Character Spritesheets](/docs/generateCharacterSpritesheet) +- [Customizing Sprite Generation Options](/docs/customizeSpriteOptions) + +Remember, the available styles may be updated over time, so always use this function to get the most up-to-date list of styles supported by the SpriteAI module. \ No newline at end of file diff --git a/docs/generateEnvironmentSprites.md b/docs/generateEnvironmentSprites.md new file mode 100644 index 00000000..1167237e --- /dev/null +++ b/docs/generateEnvironmentSprites.md @@ -0,0 +1,119 @@ +--- +title: Generate Environment Sprites +description: Learn how to use the generateEnvironmentSprites function to create tileset images for game environments. +sidebar_position: 4 +--- + +# Generate Environment Sprites + +## Introduction + +The `generateEnvironmentSprites` function is a powerful tool for game developers to quickly generate tileset images for various game environments. This tutorial will guide you through using this function to create custom environment sprites using AI-powered image generation. + +## Prerequisites + +- Node.js installed on your system +- 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 { generateEnvironmentSprites } from './path/to/spriteAI'; +``` + +## Basic Usage + +Here's a simple example of how to use the `generateEnvironmentSprites` function: + +```javascript +const description = "medieval fantasy forest"; +const result = await generateEnvironmentSprites(description); +console.log(result); +``` + +This will generate a tileset of medieval fantasy forest environment elements. + +## Customizing Your Environment Sprites + +The `generateEnvironmentSprites` function accepts an options object as its second parameter, allowing you to customize various aspects of the generated sprites. + +Here's an example with custom options: + +```javascript +const description = "futuristic cyberpunk city"; +const options = { + elements: 6, + size: '1024x1024', + style: 'vector', + padding: 2, + theme: 'sci-fi', + save: true +}; + +const result = await generateEnvironmentSprites(description, options); +console.log(result); +``` + +Let's break down the available options: + +- `elements`: Number of different environment elements to generate (default: 4) +- `size`: Size of the generated image (default: '1024x1024') +- `style`: Art style of the sprites (default: 'pixel-art') +- `padding`: Padding between elements in the tileset (default: 1) +- `theme`: Theme of the environment (default: 'fantasy') +- `save`: Whether to save the generated image to disk (default: false) + +## Understanding the Output + +The `generateEnvironmentSprites` function returns an object with the following properties: + +- `original`: URL of the original AI-generated image +- `tileset`: Base64-encoded PNG image of the processed tileset +- `metadata`: Object containing information about the generated tileset + +Here's an example of how to use the returned data: + +```javascript +const result = await generateEnvironmentSprites("tropical beach"); + +console.log("Original image URL:", result.original); +console.log("Tileset image (base64):", result.tileset); +console.log("Number of elements:", result.metadata.elements); +console.log("Theme:", result.metadata.theme); +console.log("Dimensions:", result.metadata.dimensions); +console.log("Tile layout:", result.metadata.tileData); +``` + +## Saving Generated Sprites + +If you set the `save` option to `true`, the function will automatically save the generated tileset to your project's `assets` folder. The filename will be based on the description you provided, with spaces replaced by underscores. + +For example: + +```javascript +const description = "snowy mountain landscape"; +const options = { save: true }; + +await generateEnvironmentSprites(description, options); +// Saves: ./assets/snowy_mountain_landscape_environment.png +``` + +## Best Practices + +1. Be specific in your descriptions to get the best results. +2. Experiment with different styles and themes to find what works best for your game. +3. Generate multiple variations and choose the best one for your needs. +4. Always review and potentially touch up the AI-generated sprites before using them in production. + +## Next Steps + +Now that you've learned how to generate environment sprites, you might want to explore: + +- [Generating Character Sprites](./generateCharacterSprite.md) +- [Generating Item Sprites](./generateItemSprites.md) +- [Working with Sprite Sheets in Game Engines](./workingWithSpriteSheets.md) + +Happy sprite generating! \ No newline at end of file diff --git a/docs/generateItemSprites.md b/docs/generateItemSprites.md new file mode 100644 index 00000000..5c08c9ad --- /dev/null +++ b/docs/generateItemSprites.md @@ -0,0 +1,102 @@ +--- +title: Generate Item Sprites +description: Learn how to generate item sprites for your game using AI-powered image generation. +sidebar_position: 4 +--- + +# Generate Item Sprites + +## Introduction + +The `generateItemSprites` function allows you to create a collection of item sprites for your game using AI-powered image generation. This tutorial will guide you through the process of generating a set of item sprites with customizable options. + +## Prerequisites + +- Node.js installed on your system +- The `spriteAI` module installed in your project + +## Getting Started + +First, import the `generateItemSprites` function from the `spriteAI` module: + +```javascript +import { generateItemSprites } from 'spriteAI'; +``` + +## Generating Item Sprites + +To generate item sprites, call the `generateItemSprites` function with a description and optional parameters. Here's a basic example: + +```javascript +const result = await generateItemSprites("medieval weapons", { + itemCount: 6, + style: 'pixel-art', + itemType: 'equipment' +}); + +console.log(result); +``` + +This will generate a collection of 6 medieval weapon sprites in a pixel art style. + +## Customizing Your Sprite Generation + +The `generateItemSprites` function accepts several options to customize the output: + +- `itemCount`: Number of items to generate (default: 4) +- `size`: Size of the generated image (default: "1024x1024") +- `style`: Art style of the sprites (default: "pixel-art") +- `padding`: Padding between sprites (default: 1) +- `itemType`: Type of items to generate (default: "equipment") +- `background`: Background color of the sprite sheet (default: "white") + +Here's an example with custom options: + +```javascript +const result = await generateItemSprites("magical potions", { + itemCount: 8, + size: "2048x2048", + style: "hand-drawn", + itemType: "consumable", + background: "transparent" +}); +``` + +## Understanding the Result + +The `generateItemSprites` function returns an object containing: + +- `original`: URL of the original generated image +- `itemSheet`: Base64-encoded image data of the processed sprite sheet +- `metadata`: Object containing information about the generated sprites + +Example of accessing the metadata: + +```javascript +const { metadata } = await generateItemSprites("space gadgets"); + +console.log(`Generated ${metadata.itemCount} items`); +console.log(`Image dimensions: ${metadata.dimensions.width}x${metadata.dimensions.height}`); +``` + +## Saving the Generated Sprites + +To save the generated sprite sheet to disk, use the `save` option: + +```javascript +await generateItemSprites("fantasy armor", { + save: true +}); +``` + +This will save the sprite sheet in your project's `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 use generated sprites in your game engine](/docs/using-sprites-in-game) +- [Customizing sprite generation with advanced prompts](/docs/advanced-sprite-prompts) +- [Integrating sprite generation into your asset pipeline](/docs/asset-pipeline-integration) + +Remember, the AI-generated sprites are a starting point. You may want to refine them further or use them as inspiration for your final game assets. \ No newline at end of file diff --git a/docs/generateSprite.md b/docs/generateSprite.md index 8254a0c8..b1a28a70 100644 --- a/docs/generateSprite.md +++ b/docs/generateSprite.md @@ -1,54 +1,142 @@ --- +title: Sprite Generation and Management +description: >- + Learn how to generate and manage sprite sheets, environment sprites, and item + sprites using AI-powered tools. slug: / sidebar_position: 1 --- -# generateSprite Documentation +# Sprite Generation and Management -## Brief Description -`generateSprite` is a function that generates a sprite sheet image based on a given description, using AI-powered image generation and analysis. +## Introduction -## Usage -To use `generateSprite`, import it from the sprite module and call it with a description of the character you want to generate. +This tutorial will guide you through using our AI-powered sprite generation tools to create character spritesheets, environment sprites, and item sprites for your game development projects. You'll learn how to use the `generateCharacterSpritesheet`, `generateEnvironmentSprites`, and `generateItemSprites` functions, as well as how to fetch available animation states and sprite styles. + +## Prerequisites + +- Node.js installed on your system +- Basic understanding of JavaScript and async/await syntax +- OpenAI API key (for image generation) + +## Getting Started + +First, let's import the necessary functions from the sprite module: + +```javascript +import { + generateCharacterSpritesheet, + generateEnvironmentSprites, + generateItemSprites, + fetchAvailableAnimationStates, + fetchAvailableSpriteStyles +} from './path/to/sprite/module'; +``` + +## Generating a Character Spritesheet + +Let's create a character spritesheet for a medieval knight: ```javascript -import { sprite } from './path/to/sprite/module'; +async function createKnightSpritesheet() { + const options = { + states: ['idle', 'walk', 'attack'], + framesPerState: 4, + size: '1024x1024', + style: 'pixel-art', + direction: 'right' + }; + + const result = await generateCharacterSpritesheet("medieval knight in armor", options); + + console.log("Spritesheet URL:", result.spritesheet); + console.log("Metadata:", result.metadata); +} -const result = await sprite.generateSprite(description, options); +createKnightSpritesheet(); ``` -## Parameters -- `description` (string, required): A text description of the character to generate. -- `options` (object, optional): - - `iterations` (number): Number of sprite variations to generate. - - `size` (string): Size of the generated image (default: "1024x1024"). - - `save` (boolean): Whether to save the generated image to disk. +This will generate a spritesheet with idle, walk, and attack animations for a medieval knight character. -## Return Value -Returns an object or array of objects containing: -- `messages`: JSON object with frameHeight and frameWidth information. -- `image`: Base64-encoded image data URL of the generated sprite sheet. +## Generating Environment Sprites -## Examples +Now, let's create some environment sprites for a forest setting: -1. Generate a single sprite sheet: ```javascript -const result = await sprite.generateSprite("A pixelated robot"); -console.log(result.messages); -console.log(result.image); +async function createForestEnvironment() { + const options = { + elements: 6, + size: '1024x1024', + style: 'pixel-art', + theme: 'fantasy' + }; + + const result = await generateEnvironmentSprites("forest with trees and bushes", options); + + console.log("Environment Tileset URL:", result.tileset); + console.log("Metadata:", result.metadata); +} + +createForestEnvironment(); ``` -2. Generate multiple variations: +This will generate a tileset with 6 different forest elements in a pixel art style. + +## Generating Item Sprites + +Let's create some item sprites for medieval weapons: + ```javascript -const variations = await sprite.generateSprite("A cartoon cat", { iterations: 3 }); -variations.forEach((variation, index) => { - console.log(`Variation ${index + 1}:`, variation.messages); -}); +async function createWeaponItems() { + const options = { + itemCount: 4, + size: '512x512', + style: 'pixel-art', + itemType: 'equipment' + }; + + const result = await generateItemSprites("medieval weapons including sword and bow", options); + + console.log("Item Sheet URL:", result.itemSheet); + console.log("Metadata:", result.metadata); +} + +createWeaponItems(); ``` -## Notes or Considerations -- The function uses AI models (DALL-E 3 and GPT) to generate and analyze images, which may result in varying outputs for the same input. -- Generated sprites are optimized for walking animations and follow a specific layout (6 frames in a 2x3 grid). -- The function converts images to grayscale, which may affect the final output. -- When saving images, they are stored in an 'assets' folder with a filename based on the description. -- The function may take some time to complete due to API calls and image processing. +This will generate a sheet with 4 different medieval weapon sprites. + +## Fetching Available Animation States and Styles + +You can retrieve the list of available animation states and sprite styles: + +```javascript +async function getAvailableOptions() { + const animationStates = await fetchAvailableAnimationStates(); + console.log("Available Animation States:", animationStates); + + const spriteStyles = await fetchAvailableSpriteStyles(); + console.log("Available Sprite Styles:", spriteStyles); +} + +getAvailableOptions(); +``` + +## Outcome + +After running these functions, you'll have: + +1. A character spritesheet for a medieval knight +2. A set of forest environment sprites +3. A set of medieval weapon item sprites +4. Lists of available animation states and sprite styles + +You can use these generated assets in your game development project. + +## Next Steps + +- Learn how to integrate these sprites into your game engine +- Explore advanced options for sprite generation, such as custom color palettes or animation speeds +- Check out our How-To guides for tips on optimizing and using these sprites effectively in your games + +By following this tutorial, you've learned how to generate various types of sprites using AI-powered tools. These functions provide a quick and easy way to create game assets, allowing you to focus more on game mechanics and less on asset creation.