본문으로 건너뛰기
Skillpedia
일반 코딩6.4k · #14203

melonjs-getting-started

하는 일

melonJS 20 게임을 시작하는 방법을 설명합니다. 필수 설정 단계와 첫 오브젝트를 추가하는 방법을 포함합니다. 브라우저 게임을 새로 시작하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓개발자가 새 melonJS 게임을 시작하고 첫 번째 작동 화면이 필요할 때.
  • ✓개발자의 오브젝트는 추가했지만 화면에 전혀 나타나지 않을 때.
  • ✓개발자가 게임이 어떤 렌더러를 사용할지 알아야 할 때.

스킬 링크

https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-getting-started/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-getting-started/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“가운데에 제목 텍스트가 있는 기본 melonJS 게임을 만들어 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 설정 순서를 보여 줍니다. 앱을 만들고, 초기화를 await로 기다린 다음, 오브젝트를 월드 컨테이너에 추가합니다. 렌더러 대체 방식도 설명합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Getting started with melonJS

Bootstrapping a melonJS 20.x game: the Application lifecycle, the mandatory await app.init(), the world container, and what the renderer fallback means for feature availability.

Applies to: melonJS 20.x. Older major versions differ — see the melonjs-20-migration skill.

The bootstrap

Application construction is synchronous but initialisation is not. init() returns a promise and must be awaited before building any renderable, loading assets, or entering a scene.

import { Application, Text } from "melonjs";

const app = new Application(1218, 562, {
    parent: "screen",      // id of the DOM element to mount into
    scale: "auto",
    backgroundColor: "#202020",
});
await app.init();          // ← REQUIRED. Nothing below works without it.

app.world.addChild(
    new Text(609, 281, {
        font: "Arial",
        size: 160,
        fillStyle: "#FFFFFF",
        textAlign: "center",
        textBaseline: "middle",
        text: "Hello World !",
    }),
);

This is the single most common thing to get wrong. On 19.x the constructor called init(width, height, options) for you; on 20.x init() takes no arguments and calling — and awaiting — it is your job. Nothing that follows names the missing call. The constructor does build app.world, so adding a plain renderable succeeds and simply never draws — no canvas is appended and the app never subscribes to the frame tick — while constructing a Sprite or a Text throws Cannot read properties of undefined (reading 'renderer'), because the global game those two fall back on is only set once the first init() resolves. Either way app.renderer and app.viewport stay undefined and the page stays blank.

init() is asynchronous because acquiring a WebGPU device is asynchronous. There is no synchronous alternative.

Top-level await

The bootstrap needs await at module scope. In an ES module that is fine. If the surrounding tooling does not allow it, wrap it:

async function main() {
    const app = new Application(800, 600, { parent: "screen" });
    await app.init();
    // …
}
void main();

Choosing a renderer

video.AUTO (the default) tries WebGPU → WebGL 2 → Canvas and uses the first that works.

import { video } from "melonjs";

const app = new Application(800, 600, {
    parent: "screen",
    renderer: video.AUTO,      // default; or video.WEBGPU / video.WEBGL / video.CANVAS
});

Two consequences worth knowing before writing rendering code:

  • Which backend you get is a runtime fact, not a build-time one. The same code runs on a different renderer depending on the machine. Do not assume WebGL.
  • Not every feature exists on every backend. Shader effects and post effects need a programmable pipeline and are inert on Canvas. Where a feature degrades, the engine warns once rather than throwing — so a missing effect is a console warning, not a crash.

Pin the renderer explicitly (video.WEBGL) only when you have a reason to. It costs you the WebGPU path and the Canvas fallback.

The scene graph

app.world is the root Container. Everything drawn is a descendant of it.

app.world.addChild(sprite, 10);   // 10 is the z / draw order

Pass the z-order as the second argument to addChild — it is the only form that works. renderable.z does not exist as a property, setting depth before addChild is overwritten by autoDepth, and setting it afterwards does not resort. See the melonjs-renderables skill for the full explanation.

Scenes

For anything beyond a single screen, use Stage subclasses and the state manager rather than mutating app.world directly:

import { Stage, state } from "melonjs";

class PlayScreen extends Stage {
    onResetEvent() { /* build the scene */ }
    onDestroyEvent() { /* tear it down */ }
}

state.set(state.PLAY, new PlayScreen());
state.change(state.PLAY);

onResetEvent runs every time the state is entered, not once — build scene content there, not in the constructor.

Loading assets

Assets are declared and preloaded through loader; audio needs audio.init() with the formats you ship before any audio asset is preloaded.

import { audio, loader } from "melonjs";

audio.init("mp3,ogg");                             // BEFORE preloading audio
await loader.preload([
    { name: "tileset", type: "image", src: "data/img/tileset.png" },
    { name: "jump",    type
자주 묻는 질문

화면에 아무것도 그려지지 않는 이유는 무엇인가요?

버전 20에서는 아무것도 추가하기 전에 앱을 await로 초기화해야 하며, 그러지 않으면 오브젝트가 그려지지 않습니다.

월드 컨테이너란 무엇인가요?

게임 오브젝트를 추가해 게임 안에 나타나게 하는 곳입니다.

렌더러 대체 방식이란 무엇인가요?

가능하면 WebGPU 또는 WebGL 2를 사용하고, 그렇지 않으면 일부 기능이 없는 Canvas로 대체합니다.

상세 정보

작성자의 원본 설명

Use this skill when starting or bootstrapping a melonJS game, creating the Application, choosing a renderer, or setting up the first scene. Covers the mandatory async init, the world container, adding renderables, and the WebGPU/WebGL 2/Canvas fallback. Triggers on: melonjs, new Application, app.init, app.world, video.AUTO, video.WEBGL, video.CANVAS, Stage, state.change, getting started, bootstrap.

repo: melonjs/melonJS

인기도

GitHub 스타
6.4k
순위
#14203
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬