Community연구 & 데이터 분석github.com

melonjs/melonjs-장면-및-상태

melonJS의 장면 구조와 게임 흐름을 다루는 스킬입니다 — Stage 서브클래스, 상태 관리자, 전환, 일시정지, 업데이트 루프, 타이머 및 트윈을 포함합니다. onResetEvent와 생성자의 차이, state.set 후 state.change 사용, 스테이지별 카메라 및 월드 라이프사이클, 일시정지 인식 타이밍을 다룹니다.

melonjs-장면-및-상태란 무엇인가요?

이 스킬은 melonJS 게임 엔진에서 장면(Scene) 구조와 게임 흐름을 관리하는 방법을 제공합니다. 개발자는 `me.Stage` 서브클래스를 정의하고 `me.state`를 통해 장면 간 전환을 제어할 수 있으며, `onResetEvent`, `onDestroyEvent`, `onActivateEvent`, `onDeactivateEvent` 등의 생명주기 메서드를 활용하여 각 장면의 초기화와 정리를 수행할 수 있습니다. 또한 `state.set`과 `state.change`의 차이를 이해하고, 카메라와 월드 객체의 스테이지별 생명주기를 올바르게 처리하며, `me.timer`, `setTimeout`, `setInterval` 및 `Tween`을 사용한 일시정지 인식 타이밍 기능을 구현할 수 있습니다. 이 스킬은 주로 Cursor, Codex, Claude Code 등 AI 코딩 에이전트에서 `Stage`, `state.set`, `state.change`, `onResetEvent` 등의 키워드가 감지될 때 자동으로 활성화되어 관련 코드 생성 및 리팩토링을 지원합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/melonjs/melonJS/tree/master/packages/melonjs/skills/melonjs-scenes-and-state

Installed? Explore more 연구 & 데이터 분석 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

melonjs-장면-및-상태은(는) 무엇을 하나요?

이 스킬은 melonJS의 장면 구조와 게임 흐름을 다룹니다 — Stage 서브클래스, 상태 관리자, 전환, 일시정지, 업데이트 루프, 타이머 및 트윈을 포함합니다. onResetEvent와 생성자의 차이, state.set 후 state.change 사용, 스테이지별 카메라 및 월드 라이프사이클, 일시정지 인식 타이밍을 다룹니다. 다음 키워드에서 트리거됩니다: Stage, state, state.set, state.change, state.transition, state.pause, onResetEvent, onDestroyEvent, onActivateEvent, onDeactivateEvent, PLAY, MENU, LOADING, update loop, GAME_UPDATE, timer, setTimeout, setInterval, Tween, freeze.

주요 개념

Stage 서브클래스

  • me.Stage를 상속받아 각 장면(Scene)을 정의합니다.
  • onResetEvent()는 장면이 활성화될 때마다 호출되며, 생성자와 달리 반복적인 초기화에 적합합니다.
  • 생성자는 한 번만 실행되므로 정적 리소스 로딩에 적합합니다.

상태 관리자 (me.state)

  • me.state.set()으로 상태를 등록하고, me.state.change()로 전환합니다.
  • state.set()은 등록 시, state.change()는 전환 시 호출됩니다.
  • state.transition()으로 전환 효과(페이드 등)를 추가할 수 있습니다.
  • state.pause()로 현재 장면을 일시정지하고 state.resume()으로 재개합니다.

생명주기 메서드

  • onResetEvent(): 장면이 활성화될 때마다 호출됩니다.
  • onDestroyEvent(): 장면이 제거되거나 다른 장면으로 전환될 때 호출됩니다.
  • onActivateEvent(): 장면이 활성화될 때(전환 직후) 호출됩니다.
  • onDeactivateEvent(): 장면이 비활성화될 때(전환 직전) 호출됩니다.

카메라 및 월드 라이프사이클

  • 각 Stage는 고유한 me.game.world와 me.game.viewport(카메라)를 가집니다.
  • 장면 전환 시 이전 장면의 월드와 카메라는 자동으로 정리됩니다.
  • 수동 정리가 필요하면 onDestroyEvent()에서 수행합니다.

업데이트 루프

  • update(dt) 메서드를 오버라이드하여 매 프레임마다 로직을 실행합니다.
  • GAME_UPDATE 이벤트를 수신하여 사용자 정의 업데이트를 추가할 수 있습니다.
  • dt는 프레임 간 시간 차이(밀리초)입니다.

타이머 및 트윈

  • me.timer.setTimeout()과 me.timer.setInterval()은 일시정지 인식 타이머입니다.
  • 게임이 일시정지되면(state.pause()) 이 타이머도 일시정지됩니다.
  • 네이티브 setTimeout/setInterval은 일시정지의 영향을 받지 않습니다.
  • me.Tween은 애니메이션을 위한 트윈 라이브러리로, 일시정지 인식이며 프레임 기반으로 작동합니다.
  • freeze()는 트윈을 일시정지하고, resume()은 재개합니다.

사용 예시

// Stage 서브클래스 정의
class MenuStage extends me.Stage {
    onResetEvent() {
        me.game.world.addChild(new me.ColorLayer("background", "#000000"));
        // 메뉴 UI 초기화
    }

    onDestroyEvent() {
        // 정리 작업
    }
}

// 상태 등록 및 전환
me.state.set(me.state.PLAY, new PlayStage());
me.state.set(me.state.MENU, new MenuStage());
me.state.transition("fade", "#000000", 250);
me.state.change(me.state.MENU);

// 일시정지 인식 타이머
me.timer.setTimeout(() => {
    console.log("이것은 게임이 일시정지되면 멈춥니다");
}, 1000);

// 네이티브 타이머 (일시정지 영향 없음)
setTimeout(() => {
    console.log("이것은 게임이 일시정지되어도 계속 실행됩니다");
}, 1000);

// 트윈 사용 예시
let myTween = new me.Tween(sprite.pos)
    .to({ x: 300, y: 200 }, 1000)
    .easing(me.Tween.Easing.Quadratic.InOut)
    .start();

// 일시정지 (트윈도 멈춤)
me.state.pause();

// 재개 (트윈도 재개)
me.state.resume();

참고 사항

  • state.set()과 state.change()는 반드시 state.set()이 먼저 호출되어야 합니다.
  • 생성자에서 무거운 리소스를 로딩하고 onResetEvent에서는 가벼운 초기화만 수행하는 것이 권장됩니다.
  • 카메라 위치는 장면 전환 시 초기화되므로 매 onResetEvent에서 설정해야 합니다.
  • me.timer의 타이머는 게임 일시정지 시 자동으로 멈추지만, 네이티브 setTimeout/setInterval은 멈추지 않습니다.

Individual skills in this repo

This repo contains 10 individual skills — each has its own dedicated page.

melonjs/melonjs-3d

Use this skill for anything 3D or 2.5D in melonJS — Camera3d, Mesh, InstancedMesh, Sprite3d billboards, Light3d, ground shadows, glTF/GLB scenes, and depth sorting. Covers the Y-down/+Z-forward convention that is the inverse of OpenGL, the cameraClass opt-in, clip planes, and what does not work on the Canvas fallback. Triggers on: Camera3d, Mesh, InstancedMesh, Sprite3d, Light3d, billboard, glTF, glb, 3D, 2.5D, depth, cameraClass, fov, setClipPlanes, setFog, fog, distance fog, height fog, heightFalloff, transparent, transparency, alpha, blendMode, fade, castGroundShadow, lit.

melonjs/melonjs-3d-assets

Use this skill when loading 3D models into melonJS — glTF and GLB scenes, OBJ/MTL models, materials, imported lights, node animation, ground shadows and GPU instancing. Covers level.load options including the async flag, the rightHanded conversion, and exactly what the loader does and does not support. Triggers on: glTF, gltf, glb, OBJ, MTL, 3D model, getGLTF, getOBJ, getMTL, GLTFModel, GLTFScene, level.load glb, rightHanded, lightIntensityScale, castGroundShadow, shadowGroundY, EXT_mesh_gpu_instancing, KHR_lights_punctual, skinning, Blender export, 3D asset.

melonjs/melonjs-camera-and-drawing

Use this skill for camera control and immediate-mode drawing in melonJS — following a target, viewport bounds, shake and fade, secondary cameras, and drawing shapes, lines and gradients inside a custom draw(). Covers world versus screen coordinate conversion, clipping and masking, and baking with CanvasRenderTarget. Triggers on: Camera2d, viewport, follow, setBounds, shake, fadeIn, fadeOut, worldToLocal, localToWorld, colorMatrix, renderer.fill, renderer.stroke, Rect, Ellipse, Polygon, Line, Gradient, clipRect, mask, CanvasRenderTarget, NoiseTexture2d.

melonjs/melonjs-effects-and-shaders

Use this skill for post-processing effects, custom shaders, blend modes and colour grading in melonJS. Covers the built-in ShaderEffect presets, addPostEffect on renderables and cameras, writing a custom dual-language GLSL/WGSL effect, the screen_texture builtins, and why effects silently do nothing on the Canvas fallback. Triggers on: ShaderEffect, addPostEffect, removePostEffect, getPostEffect, VignetteEffect, GlowEffect, BlurEffect, PixelateEffect, ScanlineEffect, shader, GLSL, WGSL, uniform, setUniform, setTexture, setTime, blendMode, colorMatrix, screen_texture, toFrameTexture, post effect, filter.

melonjs/melonjs-loading-assets

Use this skill for loading and managing game assets in melonJS — the resource descriptor format, the full asset type list, preload versus load, retrieving loaded assets, base URLs and cross-origin settings, and the loading screen. Triggers on: loader, loader.preload, loader.load, resources, getImage, getJSON, getTMX, getGLTF, getVideo, getFont, setBaseURL, setOptions, crossOrigin, withCredentials, credentials, cookies, authenticated assets, CORS, asset, preload, LOADER_COMPLETE, loading screen, unload.

melonjs/melonjs-performance

Use this skill when a melonJS game drops frames, allocates heavily, or needs to scale to many objects. Covers object pooling, draw-call batching, atlases, baking with CanvasRenderTarget, instancing, culling and alwaysUpdate, the debug plugin, and where the real costs are. Triggers on: performance, slow, frame rate, fps, lag, pool, pool.register, pool.pull, batching, draw calls, InstancedMesh, culling, alwaysUpdate, inViewport, CanvasRenderTarget, optimise, profiling, debug plugin, memory.

melonjs/melonjs-physics

Use this skill for collision, physics bodies, movement, and spatial queries in melonJS — the built-in SAT world and the planck/matter adapters. Covers bodyDef vs Body, collision types and masks, the collision callback family and their firing rules, raycast/queryAABB/querySphere, and the behaviour differences between adapters. Triggers on: Body, bodyDef, collision, collisionType, collisionMask, onCollision, onCollisionStart, onCollisionActive, raycast, queryAABB, querySphere, PlanckAdapter, MatterAdapter, gravity, velocity, applyForce, isGrounded, SAT.

melonjs/melonjs-renderables

Use this skill when subclassing Renderable, writing a custom draw() method, handling pointer or click events on game objects, applying post effects and shaders, or controlling draw order. Covers the pos-relative draw contract, isKinematic and input, addPostEffect vs the deprecated shader property, and z-ordering. Triggers on: Renderable, extends Renderable, draw(, update(, isKinematic, pointerEvent, registerPointerEvent, onClick, addPostEffect, removePostEffect, ShaderEffect, addChild, z-order, anchorPoint, floating.

melonjs/melonjs-renderer-backends

Use this skill when a feature works on one machine and not another, when choosing or pinning a renderer, or when writing code that must degrade gracefully. Covers the WebGPU to WebGL 2 to Canvas fallback ladder, what each backend supports, capability detection, and the subsystems that warn once and then stop working on Canvas. Triggers on: video.AUTO, video.WEBGPU, video.WEBGL, video.CANVAS, renderer.type, supportsDepthBuffer, shaderLanguage, WebGPU, WebGL2, Canvas fallback, context loss, backen

melonjs/melonjs-ui-and-text

Use this skill for HUDs, buttons, menus, dialogue panels and on-screen text in melonJS. Covers UIBaseElement/UISpriteElement/UITextButton, Draggable and DropTarget, the floating screen-space container pattern, Text and BitmapText, web font loading, and NineSliceSprite panels. Triggers on: UI, HUD, button, UIBaseElement, UISpriteElement, UITextButton, Draggable, DropTarget, menu, dialogue, Text, BitmapText, font, fontface, wordWrapWidth, NineSliceSprite, score display, floating.

관련 스킬