LLM Skills
~/catalogue/frontend//SKILL
Frontendsource GitHub

Adaptable et réactif

/SKILL

Utilisez cette compétence pour rendre un jeu Phaser 4 adaptatif ou pour gérer la mise à l'échelle de l'affichage. Elle couvre le ScaleManager, les mod

phaserjsphaserjs
40.3k
21 mai 2026
MIT License
// contenu du skill

name: scale-and-responsive

description: "Use this skill when making a Phaser 4 game responsive or handling display scaling. Covers ScaleManager, scale modes (FIT, RESIZE, EXPAND, ENVELOP), auto-center, fullscreen, and browser resize handling. Triggers on: ScaleManager, responsive, resize, fullscreen, FIT, scale mode."


Scale and Responsive Design

How to use the ScaleManager for scaling, centering, fullscreen, orientation handling, and responsive resize in Phaser 4.

Key source paths: src/scale/ScaleManager.js, src/scale/const/, src/scale/events/, src/core/typedefs/ScaleConfig.js

Related skills: ../game-setup-and-config/SKILL.md

Quick Start

Scale-to-fit with centering -- the most common setup for responsive games:

js
const config = {
    type: Phaser.AUTO,
    scale: {
        parent: 'game-container',
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_BOTH,
        width: 800,
        height: 600
    },
    scene: MyScene
};

const game = new Phaser.Game(config);

The scale config object is parsed into a Phaser.Core.Config instance which the ScaleManager reads during boot. The ScaleManager sets the canvas element size and applies CSS scaling to fit it within its parent.

Core Concepts

ScaleManager (src/scale/ScaleManager.js)

The ScaleManager is created during the Game boot sequence and is accessible at game.scale or this.scale from within a Scene. It extends EventEmitter.

Three internal Size components drive all calculations:

ComponentPropertyPurpose
gameSizegame.scale.gameSizeThe unmodified game dimensions from config. Used for world bounds, cameras. Read via game.scale.width / game.scale.height.
baseSizegame.scale.baseSizeThe auto-rounded gameSize. Sets the actual canvas.width and canvas.height attributes.
displaySizegame.scale.displaySizeThe CSS-scaled canvas size after applying scale mode, parent bounds, and zoom. Sets canvas.style.width / canvas.style.height.

Scaling works by keeping the canvas element dimensions fixed (baseSize) and stretching it via CSS properties (displaySize). This is equivalent to CSS transform-scale but without browser prefix issues.

The displayScale property (Phaser.Math.Vector2) holds the ratio baseSize / canvasBounds and is used internally for input coordinate transformation.

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

All modes are on Phaser.Scale.ScaleModes and are set via scale.mode in config:

ConstantValueBehavior
NONE0No automatic scaling. Canvas uses config width/height. You manage sizing yourself. If you resize the canvas externally, call game.scale.resize(w, h) to update internals.
WIDTH_CONTROLS_HEIGHT1Height adjusts automatically to maintain aspect ratio based on width.
HEIGHT_CONTROLS_WIDTH2Width adjusts automatically to maintain aspect ratio based on height.
FIT3Scales to fit inside parent while preserving aspect ratio. May leave empty space (letterbox/pillarbox). Most commonly used mode.
ENVELOP4Scales to cover the entire parent while preserving aspect ratio. May extend beyond parent bounds (content gets cropped).
RESIZE5Canvas element itself is resized to fill parent. No CSS scaling -- 1:1 pixel mapping. The gameSize, baseSize, and displaySize all change to match parent. Beware of GPU fill-rate on large displays.
EXPAND6Hybrid of RESIZE and FIT. The visible area resizes to fill the parent, and the canvas scales to fit inside that area. Added in v3.80.

Shorthand constants are also available directly on Phaser.Scale: Phaser.Scale.FIT, Phaser.Scale.RESIZE, etc.

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

Set via scale.autoCenter in config. Centering is achieved by setting CSS marginLeft and marginTop on the canvas:

ConstantValueBehavior
NO_CENTER0No auto-centering (default).
CENTER_BOTH1Center horizontally and vertically within parent.
CENTER_HORIZONTALLY2Center horizontally only.
CENTER_VERTICALLY3Center vertically only.

The parent element must have calculable bounds. If the parent has no defined width/height, centering will not work correctly.

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

Set via scale.zoom in config. Multiplies the display size:

ConstantValueBehavior
NO_ZOOM1No zoom (default).
ZOOM_2X22x zoom -- good for pixel art at low base resolution.
ZOOM_4X44x zoom.
MAX_ZOOM-1Automatically calculates the largest integer zoom that fits in the parent.

You can also pass any numeric value. The zoom affects CSS display size but not the canvas resolution.

Orientation (src/scale/const/ORIENTATION_CONST.js)

Read

// source originale publique
phaserjs/phaser
/skills/scale-and-responsive/SKILL.md
Licence : MIT License
Projet indépendant, non affilié à Anthropic. Ce skill reste la propriété de son auteur original.
// installer ce skill
Collez cette commande dans votre terminal à la racine de votre projet :
mkdir -p .claude/commands && curl -o ".claude/commands/SKILL.md" "https://raw.githubusercontent.com/phaserjs/phaser/master/skills/scale-and-responsive/SKILL.md"
Ensuite dans Claude Code, tapez /SKILL pour l'activer.
open_in_newVoir la source originale
// sauvegarder
Sauvegarde disponible après connexion.
loginSe connecter pour sauvegarder
// informations
Créateurphaserjs
Étoiles 40.3k
CatégorieFrontend
LicenceMIT License
Mis à jour21 mai 2026
Format.md
AccèsGratuit
// similaires

Skills Frontend

Voir toutarrow_forward