Using AI to Generate Images and Sprites for 2D Video Games
Practical guide to using AI models, automatic background removal and video workflows to create sprites and sprite sheets ready for 2D engines.
📋 Table of Contents
Why Use AI for 2D Art and Sprites
Main Advantages
AI allows generating characters, backgrounds and 2D sprites from text descriptions, accelerating prototyping and reducing initial illustration costs.
Many modern tools directly create game-ready sprites, including multiple character views, pixel art styles and animation sheets.
Benefits for Indie Developers
- Iterate quickly on the game's visual appearance without hiring external art.
- Create variations of enemies, items and scenarios in minutes.
- Generate reference art that can later be refined manually in traditional editors.
Typical Use Cases
Prototypes of 2D platformers, RPGs, roguelikes and mobile games benefit especially from AI for sprites, due to the need for large amounts of repetitive visual content.
Types of AI Tools for Images and Sprites
Converts text descriptions into 2D characters, enemy sprites, items and tilesets ready for engines like Unity, Godot or GameMaker.
Some services directly generate animation sheets with multiple frames or directions (up, down, left, right).
Services like Photoroom, Remove.bg, Pixelcut or Adobe Express remove backgrounds with AI in seconds, returning PNG with transparency for your sprites.
They are ideal for cleaning AI-generated images before integrating them into 2D engines.
Photoshop and Adobe Express include automatic subject selection, generative masks and AI fill to refine sprites and backgrounds.
They allow correcting outlines, cleaning artifacts and adapting the sprite to specific palettes or resolutions.
Paid vs Open Source Tools
Commercial services usually offer simple interfaces, cloud speed and models trained specifically for sprites and background removal.
Alternativas open source (modelos que puedes correr en local o en pipelines propios) permiten greater control, integration into your workflow and no credit-based usage limits.
Popular Tools for Sprites and Backgrounds
| Tool | Type | Model / Use | Approximate Price |
|---|---|---|---|
| Photoroom Background Remover | AI Background Remover | Automatic subject cropping for products and 2D characters. | Free limited + subscription plans. |
| Remove.bg | AI Background Remover | Quick background extraction to PNG for sprites. | Credits per image + monthly plans. |
| Adobe Express / Photoshop | Editing + Integrated AI | Subject selection, cropping, generative fill, advanced editing. | Creative Cloud subscription / Express plan. |
| Generadores de sprites (Makepix, InsMind, etc.) | 2D Sprite Generation | 2D characters, pixel art, animations and sprite sheets from text. | Freemium and subscription plans. |
| TexturePacker | Sprite Packer | Groups PNGs into optimized sprite sheets for over 30 engines. | Paid license with free trial. |
| Modelos open source de sprites | Local AI Model | Sprite and pixel art generation via pipelines like ComfyUI. | Free; hardware/infrastructure costs. |
Models and Practical Examples
Allows generating images up to 2K in PNG, useful for creating characters, backgrounds and 2D elements that you can then scale or adapt to your game resolution.
Ideal for sprite sheets and UI elements due to image quality and ease of use.
Practical Example
Result:
⚠️ Key Note: Nano Banana Pro adds a watermark in the lower right corner. We used a 5:4 aspect ratio to prevent it from affecting the button in that corner.
Sora can generate video and also PNG image resources with transparency, facilitating the creation of 2D assets on clean backgrounds for use as sprites.
Ideal for generating graffiti, decals, wall damage overlays, impact marks, painted signs and other visual elements that can be placed directly in game scenes without manual cropping, optimizing the workflow and maintaining clean and professional integration.
Practical Example
Result:
Imagen 4 (available in Whisk) excels in its exceptional prompt adherence and immediate photorealistic quality. It is the preferred option for quickly generating high-fidelity base assets without complex technical configurations.
Z-Imagen is an open source model you can integrate into workflows like ComfyUI to generate 2D images, with the ability to adjust steps, resolution and style control. Being local, it is ideal for repetitive sprite production pipelines without depending on cloud credits.
Practical Example
Imagen 4 (Whisk)
Result:
Z-Imagen (ComfyUI)
Result:
Workflow: Creating an Animated Sprite Sheet of a Scavenger
We will use AI to create a walking loop animation of a scavenger. We will see how to separate the frames, build the sprite sheet and bring the final animation to Unity with a practical and direct approach.
Step 1: Generate Base Sprite with Whisk
We will use Whisk to create our scavenger in a static pose. We are looking for a "post-apocalyptic" design with improvised armor.
Result:
Step 2: Animate with Image-to-Video
We will use the Flow tool de Google Labs. We load our generated image and select the Veo 3.1 fast model to animate it. In the prompt we specifically request a walking loop ("loop walk").
Result:
Step 3: Extract Frames (Python Script)
For full control, we will use a Python script with OpenCV that extracts frames automatically. The script is configured to save only every 3 frames, since many 2D games do not require extreme fluidity and this helps us save space in sprite sheets.
# --- REQUIREMENTS ---
# 1. Python 3.x installed
# 2. OpenCV Library: Run "pip install opencv-python" in your terminal
# ------------------
import cv2
import os
import re
import tkinter as tk
from tkinter import filedialog
# Hide the main tkinter window
root = tk.Tk()
root.withdraw()
# Select the video file
video_path = filedialog.askopenfilename(title="Select the video file")
if not video_path:
print("No video selected. Exiting.")
exit()
# Video name (without extension) and simple sanitization
video_name = os.path.splitext(os.path.basename(video_path))[0]
# Replace any sequence of non-alphanumeric characters with an underscore
safe_name = re.sub(r'[^A-Za-z0-9]+', '_', video_name).strip('_')
# Create output folder next to the video: _frames
video_dir = os.path.dirname(video_path)
output_folder = os.path.join(video_dir, f"{safe_name}_frames")
os.makedirs(output_folder, exist_ok=True)
# Open the video
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Could not open the video. Check the file.")
exit()
frame_idx = 0 # read frames counter
saved_count = 0 # saved frames counter
STEP = 3 # save only every 3 frames
while True:
ret, frame = cap.read()
if not ret:
break
if frame_idx % STEP == 0:
frame_filename = os.path.join(output_folder, f"{saved_count:03d}.jpg")
cv2.imwrite(frame_filename, frame)
saved_count += 1
frame_idx += 1
cap.release()
print(f"Leídos {frame_idx} frames. Guardados {saved_count} frames en '{output_folder}'")
We run the extract_frames.py script directly from the Windows terminal.
The script generated a total of 64 frames. After reviewing them, we selected a sequence of 12 frames (from 30 to 41) that form a complete and smooth walking cycle (seamless loop).
Step 4: Remove Background (Background Removal)
We process the 12 selected frames to remove the grey/solid background and leave only the character with transparency.
Tools: Photoroom, Remove.bg o acciones por lotes en Photoshop.
Step 5: Pack in TexturePacker
We import the clean sequence into TexturePacker. We select the "MaxRects" algorithm and the Unity-compatible data format.
Step 6: Integration in Unity
We import the Texture Sheet and data file into Unity. We use the Sprite Editor to verify the "Slicing" and create the animation by dragging the frames to the scene.
Best Practices for Generating Sprites with AI
Prompts and Recommended Background
- Write prompts in English to better leverage trained models.
- Request a uniform light grey or "light grey solid background" to facilitate cropping.
- Specify pose, angle (side view, 3/4 view), resolution and style (pixel art, flat, anime).
- If the engine requires it, request “consistent lighting” y “same proportions” to maintain consistency between sprites.
Cropping and Post-processing
- After generating, pass the image through Photoroom, Remove.bg or Adobe Express to get PNG with transparency.
- Correct outlines, lines and colors in Photoshop, GIMP or Krita before exporting as the final sprite.
- Ensure all sprites of the same character have the same canvas size and pivot point.
Recommended Workflow with TexturePacker
1) Generate images or frames with AI → 2) Remove background with background remover tool → 3) Clean details in your editor → 4) Export PNG → 5) Use TexturePacker to create the final sprite sheet.
Walk Sprite Sheet - Scavenger
Conclusion
Integrating AI into Your 2D Pipeline
AI does not replace traditional art, but it does allow rapid prototyping, visual idea validation and producing large volumes of sprites with fewer resources.
By combining image generators, background removal tools and packers like TexturePacker, you can build a solid sprite creation workflow for your 2D games.
Post a Comment