phaserjs/phaser/loading-assets
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Load files with the Phaser 4 Loader (this.load): images, spritesheets, atlases (JSON, XML, multiatlas, Aseprite, compact atlasPCT), compressed textures, audio, video, JSON, tilemaps, fonts and packs. Covers preload vs this.load.start(), setBaseURL/setPath/setPrefix and the loader config, progress events, retries, aborting with an AbortSignal (4.3), CORS and the caches. Use when making a loading screen or progress bar, a preloader Scene, loading levels on demand, or when a file fails to load or a texture from another domain shows nothing. Corrects old habits: maxRetries is 5 with backoff, a duplicate key is skipped silently, listeners use Phaser.Loader.Events constants. Triggers on: preload, this.load, spritesheet, atlas, asset pack, loading screen, progress bar, loaderror, CORS, AbortController, this.cache.
Install
npx vskill@latest install phaserjs/phaser/loading-assetsSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/loading-assets.
Loading Assets
The Loader (this.load) queues files, downloads them in parallel, and puts them into global caches that every Scene shares.
Source: src/loader/LoaderPlugin.js, src/loader/File.js, src/loader/filetypes/, src/loader/events/, src/cache/CacheManager.js. Related: scenes, audio-and-sound, animations, text-and-bitmaptext, game-setup-and-config.
Quick start
The Loader starts by itself after preload(). Anywhere else, you must start it (see below).
File types
Every method also takes a config object ({ key, url, ... }) or an array of them. A relative URL gets baseURL + path in front.
| Method | Notes | |
|---|---|---|
image(key, url) | url can be [ texture, normalMap ] for lighting | |
spritesheet(key, url, { frameWidth, frameHeight, startFrame, endFrame, margin, spacing }) | Fixed-size frames, by index | |
atlas(key, textureURL, atlasURL) | JSON Hash or Array (TexturePacker). atlasXML, unityAtlas for other formats | |
multiatlas(key, atlasURL, path, baseURL) | One JSON, many images | |
atlasPCT(key, atlasURL, path, baseURL) | Phaser Compact Texture atlas (.pct), one or more pages | |
aseprite(key, textureURL, atlasURL) | Then this.anims.createFromAseprite(key), see animations | |
texture(key, { ASTC, ETC, S3TC, ..., IMG }) | Compressed textures. WebGL only | |
svg(key, url, { width, height, scale }) | Rasterised to a texture | |
audio(key, urls, config) / audioSprite(key, jsonURL, audioURLs) | See audio-and-sound | |
video(key, urls, noAudio) | Only picks a playable URL: the Video Game Object streams it later | |
json(key, url, dataKey), xml, text, binary, html, css | dataKey keeps one property, such as 'level1.enemies' | |
tilemapTiledJSON(key, url), tilemapCSV, tilemapImpact | tilemapImpact is JSON too | |
bitmapFont(key, textureURL, fontDataURL) | XML font data only | |
font(key, url, format, descriptors) | Web font through the FontFace API. format defaults to 'truetype' | |
glsl(key, url) | Shader source into this.cache.shader, see custom-rendering | |
animation(key, url) | JSON passed to this.anims.fromJSON | |
pack(key, url), script, scripts, plugin, scenePlugin, sceneFile, htmlTexture |
Use spritesheet for a grid of same-sized frames, and atlas for packed frames with names.
URLs, keys and the loader config
- Each setting applies to the files added after it, so set it first. Since 4.3 this includes the base URL: a file keeps the base URL the Loader had when the file was added.
- Absolute URLs (
http://,https://,//,data:,blob:) skip the path and base URL. setPathandsetBaseURLadd the trailing/. If you setthis.load.pathdirectly, add it yourself.- With no URL, the key and the default extension make one:
this.load.image('logo')loadslogo.png. - The Loader is reset each time its Scene starts, back to the Scene's or game's loader config.
The defaults for every Scene go in the game config:
A Scene can override these with a loader object in its own Scene config. src/core/typedefs/LoaderConfig.js lists every key.
Progress and events
Events are emitted by this.load. Its listeners are removed when the Scene shuts down, so you don't need to remove them.
| Constant | String | Arguments | |
|---|---|---|---|
START | 'start' | (loader) | |
ADD | 'addfile' | (key, type, loader, file) | |
PROGRESS | 'progress' | (value), 0 to 1. It can go down if files are added while loading | |
FILE_PROGRESS | 'fileprogress' | (file, percent), XHR files only | |
FILE_LOAD | 'load' | (file), downloaded but not yet processed | |
FILE_LOAD_RETRY | 'loadretry' | (file, event, retries) (4.3) | |
FILE_LOAD_ERROR | 'loaderror' | (file, event), after the last retry | |
FILE_COMPLETE | 'filecomplete' | (key, type, data), processed and cached | |
FILE_KEY_COMPLETE | 'filecomplete-' | Add type + '-' + key, such as 'filecomplete-image-sky' | |
POST_PROCESS | 'postprocess' | (loader) | |
COMPLETE | 'complete' | (loader, totalComplete, totalFailed) |
The Scene's own update() doesn't run until create() has.
Loading outside preload
- Without
start()nothing loads. If the Loader is already running,start()does nothing, and the new files join the current load. - To add files that depend on another, listen for its key event during the load:
this.load.once(Phaser.Loader.Events.FILE_KEY_COMPLETE + 'json-level1', (key, type, data) => this.load.image(data.images)).
Packs
A pack is a JSON file listing files. Each section can set its own baseURL, path, prefix and defaultType, and each entry is the config object of a load method, with a type:
this.load.pack('level1', 'assets/pack.json')loads every section. Pass a section name as the third argument (dataKey) to load only that one. The second argument can also be the pack object itself.- A section's
baseURLworks since 4.3. Before, it was ignored. this.load.removePack('level1')removes the textures, animations and cache entries a loaded pack added.- A
packin the Scene config (super({ key: 'Boot', pack: { files: [ ... ] } })) loads beforepreload()runs, so a progress bar can use its images.
Retries, timeouts and aborting
- A request that errors or times out is retried
maxRetriestimes, 5 by default, waiting 100 ms and doubling up to 5 s between tries (4.3). So a network or CORS failure takes about 3 s to emitloaderror. Setloader: { maxRetries: 0 }to fail at once. - An HTTP error status, such as 404, fails at once without retries.
- For one file, pass
xhrSettings: { maxRetries: 1, timeout: 5000 }in its config object.this.load.maxRetriesapplies to files added after you change it.file.retriescounts the retries so far, andfile.retryAttemptsis how many are left. - The
loaderconfig'suserandpasswordapply to every XHR request (fixed in 4.3). ItstimeoutandwithCredentialsare currently ignored (an engine issue), so set those per file inxhrSettings. - A Loader can abort its requests with an
AbortSignal(4.3). An aborted file fails at once, with no retries, and emitsloaderror. A file which starts after the abort isn't requested.
The signal only affects files loaded with XHR. It does nothing to HTML5 Audio, video, fonts, or images when imageLoadType is 'HTMLImageElement'.
Assets from another domain (CORS)
- The server must send CORS headers. Without them an XHR load fails, and is retried before
loaderror. - Set
this.load.setCORS('anonymous')(orloader.crossOrigin) before loading images withimageLoadType: 'HTMLImageElement', and videos. Without it, WebGL can't use them. - Since 4.3, a Video from another domain loaded without CORS stops, logs a warning, and emits
VIDEO_ERROR(Phaser.GameObjects.Events.VIDEO_ERROR) rather than throwing. loader.localScheme(default[ 'file://', 'capacitor://' ]) lists schemes where a status of 0 counts as success. It has nothing to do with CORS.
Compact and compressed textures
- PCT decoded data is kept in
this.cache.atlas. The format is indocs/Phaser Compact Texture Atlas Format Specification/. - Compressed texture URLs need their extension, PVR or KTX containers. Each format can also be
{ type: 'PVR', textureURL, atlasURL }or{ multiAtlasURL, multiPath }for an atlas. Sizes, colour spaces and tools are indocs/WebGL Compressed Textures/.
Fonts
A web font which fails only logs a warning: no loaderror. See text-and-bitmaptext.
Caches
Textures go into the Texture Manager (this.textures). Everything else goes into this.cache: json, text, xml, binary, html, audio, video, shader, tilemap, bitmapFont, atlas, physics, plus this.cache.addCustom(name).
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/loading-assets/SKILL.md
Popularity
- Repository stars
- 39,633
- Repository forks
- 7,130
- 7-day trend score
- 53
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phaserjs/phaser/loading-assets)