remix-add-sprite
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd Sprite to Game Workflow
为游戏添加精灵图的工作流程
Overview
概述
This skill guides you through generating sprite sheets for canvas-based games
on the Remix platform.
本技能将指导你在Remix平台上为基于Canvas的游戏生成精灵图。
Prerequisites
前提条件
- The game HTML file must already exist (follow the game-creation workflow first if starting from scratch).
- A game must be created on the Remix platform (you need a game ID).
- The environment variable must be set.
REMIX_API_KEY
- 游戏HTML文件必须已存在(如果从零开始,请先遵循game-creation工作流程)。
- 已在Remix平台上创建游戏(你需要一个gameId)。
- 已设置环境变量。
REMIX_API_KEY
Steps
步骤
1. Check for Existing Game ID
1. 检查现有Game ID
Read in the current directory. If it exists and contains
a , use that value.
.remix-settings.jsongameIdOnly if does not exist or has no should you
follow the upload-game workflow to create one.
.remix-settings.jsongameId读取当前目录下的文件。如果该文件存在且包含,则使用该值。
.remix-settings.jsongameId只有当不存在或没有时,才需要遵循upload-game工作流程来创建一个。
.remix-settings.jsongameId2. Generate the Sprite Sheet
2. 生成精灵图
Call the sprite generation endpoint:
POST https://api.remix.gg/v1/games/{gameId}/sprites/generate
Authorization: Bearer $REMIX_API_KEY
Content-Type: application/json
{
"prompt": "a pixel-art knight walking animation, 4 frames",
"gridSize": 4,
"imageUrl": null
}Parameters:
- (required) -- description of the sprite and animation
prompt - (optional) -- number of frames in the sprite sheet grid
gridSize - (optional) -- reference image URL to base the sprite on
imageUrl
The response returns and directly (already
hosted -- no separate upload step needed).
spriteUrltransparentSpriteUrl调用精灵图生成接口:
POST https://api.remix.gg/v1/games/{gameId}/sprites/generate
Authorization: Bearer $REMIX_API_KEY
Content-Type: application/json
{
"prompt": "a pixel-art knight walking animation, 4 frames",
"gridSize": 4,
"imageUrl": null
}参数说明:
- (必填)—— 精灵图及动画的描述
prompt - (可选)—— 精灵图网格中的帧数
gridSize - (可选)—— 用于生成精灵图的参考图片URL
imageUrl
接口响应会直接返回和(已托管,无需单独上传)。
spriteUrltransparentSpriteUrl3. Integrate the Sprite Sheet into the Game
3. 将精灵图集成到游戏中
Use the returned URL with canvas to render individual frames:
drawImagejs
const sprite = new Image();
sprite.src = "https://returned-sprite-url.png";
const frameWidth = 64; // width of a single frame
const frameHeight = 64; // height of a single frame
const totalFrames = 4;
let currentFrame = 0;
sprite.onload = () => {
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw the current frame from the sprite sheet
ctx.drawImage(
sprite,
currentFrame * frameWidth, 0, // source x, y in the sprite sheet
frameWidth, frameHeight, // source width, height
player.x, player.y, // destination x, y on canvas
frameWidth, frameHeight // destination width, height
);
currentFrame = (currentFrame + 1) % totalFrames;
requestAnimationFrame(animate);
}
animate();
};Use when you need the sprite rendered over other
game elements without a background.
transparentSpriteUrl使用返回的URL,通过Canvas的方法渲染单个帧:
drawImagejs
const sprite = new Image();
sprite.src = "https://returned-sprite-url.png";
const frameWidth = 64; // 单帧宽度
const frameHeight = 64; // 单帧高度
const totalFrames = 4;
let currentFrame = 0;
sprite.onload = () => {
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// 从精灵图绘制当前帧
ctx.drawImage(
sprite,
currentFrame * frameWidth, 0, // 精灵图中的源坐标x、y
frameWidth, frameHeight, // 源宽高
player.x, player.y, // 画布上的目标坐标x、y
frameWidth, frameHeight // 目标宽高
);
currentFrame = (currentFrame + 1) % totalFrames;
requestAnimationFrame(animate);
}
animate();
};当你需要精灵图在游戏元素上无背景渲染时,请使用。
transparentSpriteUrlTips
提示
- Be specific about frame count and action. "4-frame walk cycle" is better than "walking character".
- Specify art style. Include "pixel-art", "hand-drawn", "flat vector", etc. in your prompt.
- Frame layout is horizontal. Frames are arranged left-to-right in a single
row. Divide the image width by to get individual frame dimensions.
gridSize - Use for in-game sprites that need to overlay backgrounds or other elements.
transparentSpriteUrl - Preload before gameplay. Wait for before starting the game loop.
onload
- 明确帧数和动作。“4帧行走循环”比“行走角色”的描述更准确。
- 指定艺术风格。在prompt中包含“像素风”、“手绘风”、“扁平化矢量图”等描述。
- 帧布局为水平排列。帧在单行中从左到右排列。将图片宽度除以即可得到单帧尺寸。
gridSize - 对需要叠加背景或其他元素的游戏精灵使用。
transparentSpriteUrl - 游戏开始前预加载。在启动游戏循环前等待事件触发。
onload