remix-upload-asset

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Upload 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
    REMIX_API_KEY
    environment variable must be set.
  • 游戏必须已存在于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
.remix-settings.json
in the current directory. If it exists and contains a
gameId
, use that value -- the game is already created.
Only if
.remix-settings.json
does not exist or has no
gameId
should you follow the upload-game workflow to create one.
重要提示:在检查前请勿创建新游戏。
读取当前目录下的
.remix-settings.json
文件。如果该文件存在且包含
gameId
,则使用该值——游戏已创建。
只有当
.remix-settings.json
不存在或没有
gameId
时,才应遵循upload-game工作流来创建一个新游戏。

2. 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 filename
Allowed extensions:
.jpg
,
.jpeg
,
.png
,
.webp
,
.mp3
,
.wav
,
.hdr
,
.glb
,
.gltf
Max file size: 5 MB
Response:
json
{
  "success": true,
  "data": {
    "gameId": "...",
    "asset": {
      "url": "https://..."
    }
  }
}
Use
data.asset.url
as the hosted URL for the asset.
以多部分表单数据形式发送文件:
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://..."
    }
  }
}
使用
data.asset.url
作为资源的托管URL。

3. 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_KEY

Tips

提示

  • Name files descriptively. Use clear filenames like
    player-idle.png
    or
    jump-sfx.mp3
    -- the filename becomes the default asset name.
  • Preload assets before gameplay. Wait for
    onload
    /
    canplaythrough
    events before starting the game loop to avoid missing assets.
  • Stay under 5 MB per file. Compress images and audio before uploading. Use
    .webp
    for images and
    .mp3
    for audio when possible.
  • 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。