MCPInstall

game-setup-and-config

Use this skill when creating a new Phaser 4 game instance or configuring GameConfig options. Covers renderer selection, canvas setup, scaling, pixel art, FPS settings, boot sequence, and all config sub-objects. Triggers on: new Phaser.Game, GameConfig, game setup, renderer, pixel art, FPS.

Installs
1.2K
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/phaserjs/phaser --skill game-setup-and-config
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads game-setup-and-config automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Game Setup and Config

How to create a Phaser.Game instance with the right GameConfig options for renderer, scaling, pixel art, FPS, and canvas placement.

Key source paths: src/core/Game.js, src/core/Config.js, src/core/typedefs/GameConfig.js, src/const.js, src/scale/const/ Related skills: ../scenes/SKILL.md, ../loading-assets/SKILL.md, ../scale-and-responsive/SKILL.md

Quick Start

The simplest possible Phaser 4 game -- a single scene with the default 1024×768 canvas:

class MyScene extends Phaser.Scene {
    preload() {
        this.load.image('logo', 'assets/logo.png');
    }

    create() {
        this.add.image(400, 300, 'logo');
    }
}

const config = {
    type: Phaser.AUTO,
    scene: MyScene
};

const game = new Phaser.Game(config);

new Phaser.Game(config) triggers the entire boot sequence: config parsing (Config), renderer creation, DOM insertion, and the game loop (TimeStep). The game waits for DOMContentLoaded before booting.

Core Concepts

Boot Sequence (src/core/Game.js)

  1. new Phaser.Game(config) -- parses config into a Phaser.Core.Config instance.
  2. Creates global managers: AnimationManager, TextureManager, CacheManager, InputManager, SceneManager, ScaleManager, SoundManager, TimeStep, PluginManager.
  3. Waits for DOMContentLoaded, then calls boot().
  4. boot() creates the renderer (CreateRenderer), adds the canvas to the DOM (AddToDOM), prints the debug header, emits BOOT.
  5. Once textures are ready (TextureManager emits READY), emits READY then calls start().
  6. start() begins the TimeStep loop, sets up the VisibilityHandler, calls config.postBoot.

Config Parsing (src/core/Config.js)

The Config constructor reads a flat GameConfig object and resolves defaults. Some properties can be specified at top level OR nested inside sub-objects (e.g., width can be top-level or under scale.width). The scale sub-object takes priority when both are present.

Render properties can likewise be top-level shortcuts (e.g., pixelArt: true) or nested under render.

Renderer Constants (src/const.js)

ConstantValueBehavior
Phaser.AUTO0WebGL if supported, else falls back to Canvas
Phaser.CANVAS1Force Canvas renderer
Phaser.WEBGL2Force WebGL -- no fallback if unsupported
Phaser.HEADLESS3No renderer -- DOM still required. For unit testing only

Set via config.type. Default is Phaser.AUTO.

Common Patterns

Pixel Art Game

When pixelArt is true, Config automatically sets antialias: false, antialiasGL: false, and roundPixels: true.

const config = {
    type: Phaser.AUTO,
    width: 320,
    height: 240,
    pixelArt: true,
    scale: {
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_BOTH,
        zoom: Phaser.Scale.ZOOM_2X
    },
    scene: MyScene
};

Smooth Pixel Art (WebGL only)

Preserves blocky pixels but smooths edges between them when scaled up:

const config = {
    type: Phaser.WEBGL,
    width: 320,
    height: 240,
    smoothPixelArt: true,
    scene: MyScene
};

When smoothPixelArt is true, Config sets antialias: true, antialiasGL: true, and pixelArt: false.

Full-Window Responsive Game

const config = {
    type: Phaser.AUTO,
    scale: {
        mode: Phaser.Scale.RESIZE,
        parent: 'game-container',
        width: '100%',
        height: '100%'
    },
    scene: MyScene
};

Fixed Aspect Ratio with FIT

const config = {
    type: Phaser.AUTO,
    scale: {
        mode: Phaser.Scale.FIT,
        parent: 'game-container',
        autoCenter: Phaser.Scale.CENTER_BOTH,
        width: 1280,
        height: 720,
        min: { width: 640, height: 360 },
        max: { width: 1920, height: 1080 }
    },
    backgroundColor: '#2d2d2d',
    scene: MyScene
};

Custom FPS Limit

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    fps: {
        target: 60,
        limit: 30,
        forceSetTimeOut: false,
        smoothStep: true
    },
    scene: MyScene
};

Transparent Canvas Over HTML

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    transparent: true,
    parent: 'game-container',
    scene: MyScene
};

When transparent is true, backgroundColor is forced to 0x000000 with alpha 0.

Pre-existing Canvas Element

const canvas = document.getElementById('my-canvas');

const config = {
    type: Phaser.WEBGL,
    canvas: canvas,
    width: 800,
    height: 600,
    scene: MyScene
};

Multiple Scenes

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: [BootScene, PreloadScene, MenuScene, GameScene],
    physics: {
        default: 'arcade',
        arcade: { gravity: { y: 300 } }
    }
};

Only the first scene starts automatically. Others start only if they have { active: true } in their scene config. See ../scenes/SKILL.md.

Boot Callbacks

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    callbacks: {
        preBoot: function (game) {
            // Runs before Phaser boots. Game systems not yet available.
        },
        postBoot: function (game) {
            // Runs after boot. All systems ready, game loop starting.
        }
    },
    scene: MyScene
};

Disabling Input Subsystems

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    input: {
        keyboard: true,
        mouse: true,
        touch: false,
        gamepad: false,
        activePointers: 1,
        windowEvents: true
    },
    disableContextMenu: true,
    scene: MyScene
};

Configuration Reference

Top-Level GameConfig Properties

PropertyTypeDefaultDescription
typenumberPhaser.AUTO (0)Renderer: AUTO, CANVAS, WEBGL, or HEADLESS
widthnumber|string1024Game width in pixels (or '100%'). Overridden by scale.width
heightnumber|string768Game height in pixels (or '100%'). Overridden by scale.height
zoomnumber1Canvas zoom multiplier. Overridden by scale.zoom
parentHTMLElement|string|nullundefinedDOM element or id for canvas. undefined = document body. null = no parent
canvasHTMLCanvasElementnullProvide your own canvas element
contextCanvasRenderingContext2D|WebGLRenderingContextnullProvide your own rendering context
canvasStylestringnullCSS styles applied to the canvas element
customEnvironmentbooleanfalseSkip feature detection for non-browser environments. renderType cannot be AUTO if true
sceneSceneType|SceneType[]nullScene class (extends Phaser.Scene) or array of scene classes
seedstring[][random]Seed for Phaser.Math.RND
titlestring''Game title shown in console banner
urlstring'https://phaser.io/...'Game URL shown in console banner
versionstring''Game version shown in console banner
autoFocusbooleantrueAuto-focus window on boot and mousedown
stableSortnumber|boolean-1-1 = auto-detect, 0/false = built-in stable sort, 1/true = rely on native ES2019 sort
disableContextMenubooleanfalseDisable right-click context menu
backgroundColorstring|number0x000000Canvas background color. Accepts hex number, CSS string, or color object
bannerboolean|BannerConfig(shown)false to hide console banner entirely

scale (Phaser.Types.Core.ScaleConfig)

PropertyTypeDefaultDescription
widthnumber|string1024Base game width
heightnumber|string768Base game height
zoomnumber1Zoom multiplier. Use constants: NO_ZOOM (1), ZOOM_2X (2), ZOOM_4X (4), MAX_ZOOM (-1)
parentHTMLElement|stringundefinedDOM parent for the canvas
modenumberPhaser.Scale.NONE (0)Scale mode (see table below)
expandParentbooleantrueAllow adjusting parent CSS height to 100%
autoRoundbooleanfalseRound display/style sizes for performance
autoCenternumberNO_CENTER (0)Canvas centering mode (see table below)
resizeIntervalnumber500Milliseconds between browser size checks
fullscreenTargetHTMLElement|stringnullElement for fullscreen mode
min{width, height}{0, 0}Minimum canvas dimensions
max{width, height}{0, 0}Maximum canvas dimensions (0 = no limit)
snap{width, height}{0, 0}Snap canvas size to multiples

Scale Modes (src/scale/const/SCALE_MODE_CONST.js)

ConstantValueBehavior
Phaser.Scale.NONE0No scaling. Canvas stays at config size
Phaser.Scale.WIDTH_CONTROLS_HEIGHT1Height adjusts based on width
Phaser.Scale.HEIGHT_CONTROLS_WIDTH2Width adjusts based on height
Phaser.Scale.FIT3Fit inside parent keeping aspect ratio (letterboxing)
Phaser.Scale.ENVELOP4Cover parent keeping aspect ratio (may overflow)
Phaser.Scale.RESIZE5Canvas resizes to fill parent, ignoring aspect ratio
Phaser.Scale.EXPAND6Like RESIZE for visible area + FIT for canvas scale

Center Modes (src/scale/const/CENTER_CONST.js)

ConstantValue
Phaser.Scale.NO_CENTER0
Phaser.Scale.CENTER_BOTH1
Phaser.Scale.CENTER_HORIZONTALLY2
Phaser.Scale.CENTER_VERTICALLY3

Zoom Constants (src/scale/const/ZOOM_CONST.js)

ConstantValueBehavior
Phaser.Scale.NO_ZOOM1No zoom
Phaser.Scale.ZOOM_2X22x zoom
Phaser.Scale.ZOOM_4X44x zoom
Phaser.Scale.MAX_ZOOM-1Max integer zoom that fits in parent

render (Phaser.Types.Core.RenderConfig)

These can be set at the top level OR nested under render. The render sub-object takes priority.

PropertyTypeDefaultDescription
antialiasbooleantrueLinear interpolation for scaled/rotated textures
antialiasGLbooleantrueAntialias on WebGL context creation
pixelArtbooleanfalseSets antialias: false, roundPixels: true automatically
smoothPixelArtbooleanfalseWebGL only. Blocky pixels with smooth edges
roundPixelsbooleanfalseSnap texture-based objects to integer positions
transparentbooleanfalseTransparent canvas background
clearBeforeRenderbooleantrueClear canvas each frame
preserveDrawingBufferbooleanfalsePreserve WebGL buffers between frames
premultipliedAlphabooleantruePre-multiplied alpha in WebGL drawing buffer
desynchronizedbooleanfalseDesynchronized rendering context
failIfMajorPerformanceCaveatbooleanfalseAbort WebGL if browser reports poor performance
powerPreferencestring'default''high-performance', 'low-power', or 'default'
batchSizenumber16384Max quads per WebGL batch
maxTexturesnumber-1Max GPU textures. -1 = use all available
maxLightsnumber10Max lights visible per camera
autoMobileTexturesbooleantrueRestrict to 1 texture per batch on iOS/Android
selfShadowbooleanfalseSelf-shadowing on lit textured objects
pathDetailThresholdnumber1Point-combining threshold for Graphics WebGL paths
skipUnreadyShadersbooleanfalseSkip drawing objects whose shader is still compiling
mipmapFilterstring''Mipmap filter: 'NEAREST', 'LINEAR', 'NEAREST_MIPMAP_NEAREST', etc.
renderNodesobject{}Custom render nodes for WebGL renderer

fps (Phaser.Types.Core.FPSConfig)

PropertyTypeDefaultDescription
minnumber5Minimum acceptable FPS
targetnumber60Target FPS (informational, does not enforce)
limitnumber0Enforce max FPS. 0 = no limit
forceSetTimeOutbooleanfalseUse setTimeout instead of requestAnimationFrame
deltaHistorynumber10Frames to average for delta smoothing
panicMaxnumber120Frames before trusting delta again after a panic
smoothStepbooleantrueApply delta smoothing

Other Sub-Configs

Sub-Config KeyTypeSource
callbacksCallbacksConfigsrc/core/typedefs/CallbacksConfig.js
domDOMContainerConfigsrc/core/typedefs/DOMContainerConfig.js
inputInputConfigsrc/core/typedefs/InputConfig.js
loaderLoaderConfigsrc/core/typedefs/LoaderConfig.js
physicsPhysicsConfigsrc/core/typedefs/PhysicsConfig.js
pluginsPluginObject|PluginObjectItem[]src/core/typedefs/PluginObject.js
audioAudioConfigsrc/core/typedefs/AudioConfig.js
imagesImagesConfigsrc/core/typedefs/ImagesConfig.js

Game Lifecycle, Pause/Resume, and Destroy

Game Lifecycle Events

Listen on game.events (or this.game.events from a Scene) for visibility and focus changes:

game.events.on('blur', () => { /* tab lost focus */ });
game.events.on('focus', () => { /* tab regained focus */ });
game.events.on('hidden', () => { /* Page Visibility API: page hidden */ });
game.events.on('visible', () => { /* Page Visibility API: page visible */ });
game.events.on('pause', () => { /* game.pause() was called */ });
game.events.on('resume', () => { /* game.resume() was called */ });

Use named constants: Phaser.Core.Events.BLUR, FOCUS, HIDDEN, VISIBLE, PAUSE, RESUME.

Pause and Resume

// Pause the entire game loop (rendering and updates stop)
game.pause();

// Resume the game loop
game.resume();

// Check if the game is currently paused
if (game.isPaused) {
    // game loop is not running
}

Destroying the Game

// Remove the canvas from the DOM and clean up
game.destroy(true);

// Full cleanup -- pass noReturn=true if you will NEVER create another Phaser instance
// This allows the framework to release additional internal references
game.destroy(true, true);

destroy(removeCanvas, noReturn) is asynchronous -- it flags the game for destruction on the next frame. Listen for Phaser.Core.Events.DESTROY to react to completion.

Global Game Members

The Game instance exposes key managers as properties, accessible from any Scene via this.game:

PropertyTypeDescription
game.configPhaser.Core.ConfigParsed GameConfig (read-only after boot)
game.sceneSceneManagerStart, stop, switch, and manage all scenes
game.registryDataManagerShared data store across all scenes
game.animsAnimationManagerGlobal animation definitions
game.cacheCacheManagerStores loaded non-texture assets (JSON, XML, etc.)
game.texturesTextureManagerStores all loaded textures and sprite sheets
game.soundSoundManagerGlobal sound playback manager
// Example: access the registry from any scene
this.game.registry.set('highScore', 9999);

// Example: access the scene manager
this.game.scene.start('MenuScene');

Gotchas and Common Mistakes

  1. scale vs top-level config. width, height, zoom, and parent can be set at the top level or inside scale. The scale sub-object values take priority. Avoid setting both to prevent confusion.

  2. Phaser.WEBGL has no fallback. Unlike AUTO, using Phaser.WEBGL directly will not fall back to Canvas if WebGL is unavailable. The game will fail silently.

  3. parent: null vs parent: undefined. undefined (or omitted) appends the canvas to document.body. null means Phaser will not add the canvas to the DOM at all -- you must do it yourself.

  4. transparent overrides backgroundColor. When transparent: true, the background color is forced to rgba(0,0,0,0) regardless of what you set.

  5. fps.target does not enforce frame rate. It is advisory only. Use fps.limit to actually cap the frame rate. The browser's display refresh rate is always the upper bound.

  6. fps.limit only slows down, never speeds up. Setting limit: 120 on a 60Hz display still results in 60 FPS.

  7. DOM Container requires a parent. Setting dom.createContainer: true without providing a parent element will not work.

  8. smoothPixelArt is WebGL-only. It has no effect with the Canvas renderer.

  9. window.FORCE_WEBGL and window.FORCE_CANVAS. Config.js checks for these globals at the end of parsing and will override the type setting. This is intended for development/testing.

  10. Game.destroy() is asynchronous. It flags the game for destruction on the next frame. Listen for the DESTROY event to react to completion. Pass noReturn: true only if you will never create another Phaser instance on the same page.

v4 Changes from v3

  • Default dimensions changed: Width defaults to 1024 (was 800), height to 768 (was 600).
  • EXPAND scale mode added: Phaser.Scale.EXPAND (value 6) is new -- combines RESIZE visible area behavior with FIT canvas scaling.
  • Loader maxRetries default: loader.maxRetries defaults to 2 (was 0 in early v3).
  • smoothPixelArt option: New WebGL-only rendering mode that smooths edges between blocky pixels.
  • renderNodes config: New render.renderNodes property for custom WebGL render node registration.
  • skipUnreadyShaders: New option for parallel shader compilation to prevent stutter.
  • pathDetailThreshold: New config for Graphics WebGL path point combining.

Source File Map

ConceptFile
Game class / boot sequencesrc/core/Game.js
Config parsing / all defaultssrc/core/Config.js
GameConfig typedefsrc/core/typedefs/GameConfig.js
Renderer constants (AUTO, WEBGL, CANVAS, HEADLESS)src/const.js
FPSConfig typedefsrc/core/typedefs/FPSConfig.js
RenderConfig typedefsrc/core/typedefs/RenderConfig.js
ScaleConfig typedefsrc/core/typedefs/ScaleConfig.js
Scale mode constantssrc/scale/const/SCALE_MODE_CONST.js
Center constantssrc/scale/const/CENTER_CONST.js
Zoom constantssrc/scale/const/ZOOM_CONST.js
TimeStep (game loop)src/core/TimeStep.js
Renderer creationsrc/core/CreateRenderer.js
ScaleManagersrc/scale/ScaleManager.js
CallbacksConfig typedefsrc/core/typedefs/CallbacksConfig.js
DOMContainerConfig typedefsrc/core/typedefs/DOMContainerConfig.js
InputConfig typedefsrc/core/typedefs/InputConfig.js
LoaderConfig typedefsrc/core/typedefs/LoaderConfig.js
All core typedefssrc/core/typedefs/

FAQ

What does the game-setup-and-config skill do?

Use this skill when creating a new Phaser 4 game instance or configuring GameConfig options. Covers renderer selection, canvas setup, scaling, pixel art, FPS settings, boot sequence, and all config sub-objects. Triggers on: new Phaser.Game, GameConfig, game setup, renderer, pixel art, FPS.

How do I install game-setup-and-config?

Run npx skills add https://github.com/phaserjs/phaser --skill game-setup-and-config in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/game-setup-and-config/ (personal) or .claude/skills/game-setup-and-config/ (project).

Which AI agents can use game-setup-and-config?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is game-setup-and-config safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains game-setup-and-config?

It is published by phaserjs in phaserjs/phaser. It has 1,220 recorded installs.

More from phaserjs/phaser

View all →

sprites-and-images

phaserjs/phaser

Use this skill when creating Sprites or Images in Phaser 4. Covers factory methods, texture/frame selection, position, scale, rotation, tint, flip, alpha, origin, depth, and the component mixin system. Triggers on: Sprite, Image, this.add.sprite, this.add.image, texture, setTint, setAlpha.

Media & Creative1.1K installs

animations

phaserjs/phaser

Use this skill when creating or controlling sprite animations in Phaser 4. Covers spritesheets, atlases, AnimationManager, AnimationState, play/stop/chain, frame callbacks, and animation events. Triggers on: sprite animation, spritesheet, play animation, animation frames.

Frontend & Design1.1K installs

tilemaps

phaserjs/phaser

Use this skill when working with tilemaps in Phaser 4. Covers loading Tiled JSON maps, creating tilemap layers, tile collision, dynamic tiles, tile properties, and tilemap camera culling. Triggers on: Tilemap, Tiled, tilemap layer, tile collision, tile properties.

972 installs

v4-new-features

phaserjs/phaser

Use this skill when learning about new features, game objects, components, and rendering capabilities added in Phaser 4. Covers Filters, RenderNodes, CaptureFrame, Gradient, Noise, SpriteGPULayer, TilemapGPULayer, Lighting component, RenderSteps, and new tint modes. Triggers on: new in v4, Phaser 4 features, RenderNode, SpriteGPULayer, CaptureFrame, Gradient game object, Noise game object, new tint modes. For migrating v3 code to v4, see the v3-to-v4-migration skill instead.

Media & Creative965 installs

scenes

phaserjs/phaser

Use this skill when working with Phaser 4 scenes. Covers scene lifecycle methods, scene transitions, parallel scenes, scene communication, sleeping, pausing, restarting, and the SceneManager. Triggers on: Scene, scene lifecycle, preload, create, update, scene transition, SceneManager.

956 installs

Use this skill when handling user input in Phaser 4. Covers keyboard keys, mouse clicks and movement, touch events, pointer handling, drag and drop, hit areas, interactive objects, and gamepad support. Triggers on: keyboard, mouse, touch, pointer, drag, drop, click, input, gamepad, cursor keys.

952 installs

Popular media & creative skills

View category →

hyperframes

heygen-com/hyperframes

Read first to make, edit, animate or render any video with HyperFrames (HTML rendered to video), including launch films, explainers, music videos, charts, maps, vertical clips, title cards, captions and overlays. Holds the render contract, the work loop and what each kind of video needs.

Media & Creative1.2M installs

media-use

heygen-com/hyperframes

Get or make any media for a HyperFrames video - music, sound effects, images, icons, logos, voiceover, avatar and generated video, transcripts, cutouts, colour grades and looks - with HeyGen or free local tools, and mix placed audio. Also for footage that looks dark, flat or dull, or should be stylized or hidden.

Media & Creative1.1M installs

hyperframes-registry

heygen-com/hyperframes

About 450 ready-made HyperFrames blocks and components installed as editable source - transitions, overlays, titles, kinetic type, captions, charts, map overlays, 3D, camera moves. Use it before hand-building any named visual (CRT scanlines, glitch, film grain, a chart); also for hyperframes add and catalog.

Media & Creative1M installs

hyperframes-creative

heygen-com/hyperframes

Non-animation creative direction for HyperFrames videos. Use for design spec (frame.md / design.md) handling, palettes, typography, narration, beat planning, audio-reactive visuals, composition patterns, and brand / style decisions. For atomic motion patterns and scene blueprints, use hyperframes-animation.

Media & Creative916.5K installs

ai-video-generation

101-skills/superpowers

Generate AI videos with Google Veo, Seedance 2.0, HappyHorse, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 2.0, HappyHorse 1.0, Wan 2.5, Grok Imagine Video, OmniHuman, Fabric, HunyuanVideo. Capabilities: text-to-video, image-to-video, reference-to-video, video editing, lipsync, avatar animation, video upscaling, foley sound. Use for: social media videos, marketing content, explainer videos, product demos, AI avatars. Triggers: video generation, ai video, text to video, image to video, veo, animate image, video from image, ai animation, video generator, generate video, t2v, i2v, ai video maker, create video with ai, runway alternative, pika alternative, sora alternative, kling alternative, seedance, happyhorse

Media & Creative881.5K installs

ai-image-generation

101-skills/superpowers

Generate AI images with GPT-Image-2, FLUX, Gemini, Grok, Seedream, Reve and 50+ models via inference.sh CLI. Models: GPT-Image-2, FLUX Dev LoRA, FLUX.2 Klein LoRA, Gemini 3 Pro Image, Grok Imagine, Seedream 4.5, Reve, ImagineArt. Capabilities: text-to-image, image-to-image, inpainting, LoRA, image editing, upscaling, text rendering. Use for: AI art, product mockups, concept art, social media graphics, marketing visuals, illustrations. Triggers: flux, image generation, ai image, text to image, stable diffusion, generate image, ai art, midjourney alternative, dall-e alternative, text2img, t2i, image generator, ai picture, create image with ai, generative ai, ai illustration, grok image, gemini image, gpt image, openai image, chatgpt image

Media & Creative880.3K installs