remix-upload-asset
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUpload Game Asset Workflow
上传游戏资源工作流
Overview
概述
Upload arbitrary files (images, audio, 3D models) as hosted game assets
via the REST API. Returns a permanent URL you can reference in your game HTML.
通过REST API上传任意文件(图片、音频、3D模型)作为托管游戏资源,返回一个可在游戏HTML中引用的永久URL。
Prerequisites
前提条件
- A game must already exist on the Remix platform (you need a game ID).
- The environment variable must be set.
REMIX_API_KEY
- 游戏必须已存在于Remix平台上(你需要一个游戏ID)。
- 必须设置环境变量。
REMIX_API_KEY
Steps
步骤
1. Check for Existing Game ID
1. 检查现有游戏ID
IMPORTANT: Do NOT create a new game without checking first.
Read in the current directory. If it exists and contains
a , use that value -- the game is already created.
.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. Upload the Asset
2. 上传资源
Send the file as multipart form data:
POST https://api.remix.gg/v1/games/{gameId}/assets
Authorization: Bearer $REMIX_API_KEY
Content-Type: multipart/form-data
Form fields:
file (required) — the binary file to upload
assetName (optional) — custom display name; defaults to the filenameAllowed extensions: , , , , , ,
, ,
.jpg.jpeg.png.webp.mp3.wav.hdr.glb.gltfMax file size: 5 MB
Response:
json
{
"success": true,
"data": {
"gameId": "...",
"asset": {
"url": "https://..."
}
}
}Use as the hosted URL for the asset.
data.asset.url以多部分表单数据形式发送文件:
POST https://api.remix.gg/v1/games/{gameId}/assets
Authorization: Bearer $REMIX_API_KEY
Content-Type: multipart/form-data
表单字段:
file (必填)—— 要上传的二进制文件
assetName (可选)—— 自定义显示名称;默认为文件名允许的扩展名: , , , , , ,
, ,
.jpg.jpeg.png.webp.mp3.wav.hdr.glb.gltf最大文件大小: 5 MB
响应:
json
{
"success": true,
"data": {
"gameId": "...",
"asset": {
"url": "https://..."
}
}
}使用作为资源的托管URL。
data.asset.url3. Use the URL in Game HTML
3. 在游戏HTML中使用该URL
Reference the returned URL in your game code. Examples:
html
<img src="https://returned-asset-url.png" width="64" height="64" />js
const img = new Image();
img.src = "https://returned-asset-url.png";
img.onload = () => ctx.drawImage(img, x, y, w, h);js
const audio = new Audio("https://returned-asset-url.mp3");
audio.play();在游戏代码中引用返回的URL。示例:
html
<img src="https://returned-asset-url.png" width="64" height="64" />js
const img = new Image();
img.src = "https://returned-asset-url.png";
img.onload = () => ctx.drawImage(img, x, y, w, h);js
const audio = new Audio("https://returned-asset-url.mp3");
audio.play();4. (Optional) List All Assets
4. (可选) 列出所有资源
Retrieve all uploaded assets for a game:
GET https://api.remix.gg/v1/games/{gameId}/assets
Authorization: Bearer $REMIX_API_KEY检索某款游戏的所有已上传资源:
GET https://api.remix.gg/v1/games/{gameId}/assets
Authorization: Bearer $REMIX_API_KEYTips
提示
- Name files descriptively. Use clear filenames like or
player-idle.png-- the filename becomes the default asset name.jump-sfx.mp3 - Preload assets before gameplay. Wait for /
onloadevents before starting the game loop to avoid missing assets.canplaythrough - Stay under 5 MB per file. Compress images and audio before uploading.
Use for images and
.webpfor audio when possible..mp3 - Repeat for each asset. Run through steps 2-3 for every file the game needs.
- 为文件起描述性名称。 使用清晰的文件名,如或
player-idle.png——文件名会成为默认的资源名称。jump-sfx.mp3 - 在游戏开始前预加载资源。 在启动游戏循环前等待/
onload事件,避免资源缺失。canplaythrough - 每个文件大小不超过5 MB。 上传前压缩图片和音频。尽可能使用格式的图片和
.webp格式的音频。.mp3 - 为每个资源重复操作。 为游戏所需的每个文件执行步骤2-3。