Phaser 3 项目模板,使用 Vite 打包,支持热重载与生产构建
template-youtube-playables — Vite 游戏站模板
作者 phaserjs
Phaser 3 官方示例模板,用 Vite 打包,内置 Basketball Shoot Out 示例游戏,演示 YouTube Playables SDK 的完整接入方式。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
目前有 1 张原始预览,可打开完整图片查看设计细节。
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
内置 Basketball Shoot Out 示例游戏,覆盖 YouTube Playables SDK 的各项调用
提供 YouTubePlayables.js 辅助封装,同时保留原生 SDK 调用写法
演示启动等待、首帧就绪、游戏就绪、暂停恢复等生命周期回调
演示音频开关查询与变更响应、分数上报、存档数据读写
按场景与游戏对象分目录组织源码,静态资源支持 import 内联或 public 目录加载
模板详细介绍
这是 Phaser Studio 维护的 Phaser 3 项目模板,目标场景是制作可在 YouTube Playables 平台运行的 HTML5 游戏。模板使用 Vite 作为构建与开发服务器,支持热重载,并提供生成生产构建的脚本。
模板内置一个名为 Basketball Shoot Out 的示例游戏,README 称其演示了 YouTube Playables SDK 的全部可用功能。示例围绕 SDK 的启动、加载、暂停恢复、音频状态、分数上报与存档等调用展开,并附带一个可选的 YouTubePlayables.js 辅助封装,用于处理 UTF-16 字符串校验、loadData 后的 JSON 解析等重复性工作;同时代码中也保留了原生 SDK 调用写法,便于在封装与原生 API 之间切换。
项目结构按职责划分:index.html 承载游戏页面,src/main.js 为入口与游戏配置,src/scenes 存放 Phaser 场景,src/gameobjects 存放游戏对象,public/assets 存放静态资源,public/style.css 提供基础页面布局样式。资源加载支持两种方式:通过 JavaScript import 内联打包资源,或放入 public/assets 后按路径加载。
限制方面:模板面向 YouTube Playables 平台,需要该平台的 SDK 与测试套件配合验证;README 建议在移动视图下以 iPad Pro 尺寸运行,示例玩法也是按该尺寸调整的。运行需要 Node.js 环境,本地开发服务器默认监听 8080 端口。代码采用 MIT 许可,但示例图片、字体、图标等第三方素材需单独核对许可,托管等外部服务也可能产生费用。
适合你的项目吗?
适用场景
- 为 YouTube Playables 平台开发 HTML5 小游戏时作为起步项目
- 需要参考 YouTube Playables SDK 各接口调用方式的开发场景
- 在 Phaser 3 项目中接入平台暂停、恢复与音频状态同步
- 需要向平台上报分数或读写云端存档数据的游戏
- 学习 Vite 与 Phaser 3 结合的资源加载和构建配置
适合人群
- 熟悉 JavaScript 与 Phaser 3 的游戏开发者
- 计划将游戏发布到 YouTube Playables 的团队或个人
- 需要一份可运行的 SDK 接入示例作为参考的开发者
- 使用 Vite 作为构建工具的前端游戏项目
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
需要安装 Node.js,通过 npm 安装依赖并运行脚本
- 2
npm run dev 启动本地开发服务器,默认地址为 http://localhost:8080
- 3
npm run build 生成生产构建,输出到 dist 文件夹
- 4
在 YouTube Playables 测试套件中验证时,将 http://localhost:8080 填入 Game URL
- 5
部署时需将 dist 目录的全部内容上传到公开的 Web 服务器
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 该模板面向 YouTube Playables 平台,需配合该平台 SDK 与测试套件使用,并非通用网页模板。
- 验证与发布需使用 YouTube Playables 测试套件,并依赖该平台的外部服务。
- 示例玩法按 iPad Pro 移动视图尺寸调整,其他尺寸虽可运行但体验可能不同。
- 运行与构建需要本地安装 Node.js 环境。
- Phaser 标志与角色形象版权归 Phaser Studio Inc. 所有,不在 MIT 代码许可范围内。
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
This is a Phaser 3 project template for creating YouTube Playables that uses Vite for bundling.
README 原文
To run your game in the YouTube SDK Test Suite, go to https://developers.google.com/youtube/gaming/playables/test_suite and enter `http://localhost:8080` as the Game URL.
README 原文
We recommend putting the game into Mobile View mode and picking the iPad Pro for the dimensions.
README 原文
[Node.js](https://nodejs.org) is required to install dependencies and run scripts via `npm`
README 原文
https://github.com/phaserjs/template-youtube-playables/blob/main/LICENSEhttps://github.com/phaserjs/template-youtube-playables/blob/main/README.mdThe Phaser logo and characters are © 2011 - 2024 Phaser Studio Inc.
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-03。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料一般 · 69 / 100
- 技术栈
- Vite
- 网站类型
- 游戏站
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2024-10-17
- 截图检查日期
- 2026-10-03
目前没有记录演示链接。请依据仓库说明在本地评估;仅凭截图无法确认交互行为。
目录记录的主要技术栈是 Vite。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
已完成服务器许可规则与 AI 来源核对;未经过人工编辑审核。
查看当时使用的来源资料
SHA-256: 8b868fb831c34b5cbe7a73a6dab7b9a79ffab35f5226f30ec0b052c4e172f2ce
2026-10-03T07:12:35.296Z
来源文件 / 仓库# Phaser YouTube Playables Template
This is a Phaser 3 project template for creating YouTube Playables that uses Vite for bundling. It supports hot-reloading for quick development workflow and includes scripts to generate production-ready builds.
You will find a comprehensive sample game called **Basketball Shoot Out** in this template. This game demonstrates every available feature of the YouTube Playables SDK and is explained in detail below. To test the game, install the dependencies and `npm run dev` then visit `http://localhost:8080` in your browser. We recommend putting the game into Mobile View mode and picking the iPad Pro for the dimensions. It will work at any scale, but this is the size it was built for and gameplay has been tweaked specifically for it.
### Versions
This template has been updated for:
- [Phaser 3.86.0](https://github.com/phaserjs/phaser)
- [YouTube Playables API v1](https://developers.google.com/youtube/gaming/playables/reference/sdk)
- [Vite 5.4.8](https://github.com/vitejs/vite)

## Requirements
[Node.js](https://nodejs.org) is required to install dependencies and run scripts via `npm`.
## Available Commands
| Command | Description |
|---------|-------------|
| `npm install` | Install project dependencies |
| `npm run dev` | Launch a development web server |
| `npm run build` | Create a production build in the `dist` folder |
## YouTube Playables SDK
You can access the SDK documentation at https://developers.google.com/youtube/gaming/playables/reference/sdk which is also where you will find the Test Suite, from which you can check all of the SDK calls being made from your game.
## Getting Started
After cloning the repo, run `npm install` from your project directory. Then, you can start the local development server by running `npm run dev`.
The local development server runs on `http://localhost:8080` by default. Please see the Vite documentation if you wish to change this, or add SSL support.
Once the server is running you can edit any of the files in the `src` folder. Vite will automatically recompile your code and then reload the browser.
To run your game in the YouTube SDK Test Suite, go to https://developers.google.com/youtube/gaming/playables/test_suite and enter `http://localhost:8080` as the Game URL.
## Template Project Structure
We have provided a comprehensive sample game to get you started. This is as follows:
- `index.html` - A basic HTML page to contain the game.
- `src` - Contains the game source code.
- `src/main.js` - The main entry point. This contains the game configuration and starts the game.
- `src/YouTubePlayables.js` - This is our optional YouTube Playables Helper Library.
- `src/scenes/` - The Phaser Scenes are in this folder.
- `src/gameobjects/` - The Phaser Game Objects are in this folder.
- `public/style.css` - Some simple CSS rules to help with page layout.
- `public/assets` - Contains the static assets used by the game.
## YouTube Playables Helper Library
We have included `YouTubePlayables.js` which is our helper wrapper for the Playables v1 SDK. Although the SDK is nice and easy to use, we found there were some common things we had to repeat doing, such as UTF-16 string checks, or parsing JSON after a loadData call. So, we created this open-source wrapper to help you get up to speed quickly. You can see it used through-out our sample game, but we have also included all of the native SDK calls too, so you can swap between them as needed.
### Game Boot
Calling `YouTubePlayables.boot` will wait until the document has loaded _and_ the YouTube Playables SDK is ready before calling the provided callback function:
```js
YouTubePlayables.boot(() => {
new Phaser.Game(config);
});
```
In the `Boot.js` Scene file, we get our stored game data from YouTube Playables and then set-up the global `onPause` and `onResume` handlers:
```js
async create ()
{
// This will load our saved cloud data from the Playables API.
// We use the withTimeout wrapper to ensure that the loadData call doesn't hang indefinitely
// (which can happen often in the Test Suite if you're using a hot-reloaded setup)
try
{
const data = await YouTubePlayables.withTimeout(YouTubePlayables.loadData(), 1000);
// You can also call: ytgame.game.loadData()
console.log('loadData() result', data);
}
catch (error)
{
console.error(error);
}
// We are now going to define our game pause and resume handlers.
// This is going to pause the entire Phaser game when the YouTube Playables API tells us to.
// You can also call ytgame.system.onPause(callback);
YouTubePlayables.setOnPause(() => {
console.log('YouTube Playables API has requested game pause');
this.game.pause();
});
// You can also call ytgame.system.onResume(callback);
YouTubePlayables.setOnResume(() => {
console.log('YouTube Playables API has requested game resume');
this.game.resume();
});
}
```
### Preloader
After Boot, we move to `Preloader.js` which loads all of our game assets. In here, we notify YouTube Playables that we are 'first frame ready':
```js
init ()
{
// Now we have displayed all of our loader graphics, we need to tell the YouTube Playables API that we are first-frame ready:
YouTubePlayables.firstFrameReady();
// You can also do this by calling:
// ytgame?.game.firstFrameReady();
}
```
### Main Menu
When the loading completes, we invoke the `MainMenu.js` Scene. In the `create` method, after making our game logos and buttons, we tell YouTube Playables we're now waiting for the user to interact with our game:
```js
create ()
{
// Our game is now ready to be interacted with,
// so we have to notify the YouTube Playables API about this:
YouTubePlayables.gameReady();
// You can also do this by calling:
// ytgame?.game.gameReady();
}
```
You can also query the API to know which language the user has set in YouTube and localise your game accordingly:
```js
const language = await YouTubePlayables.loadLanguage();
// You can also do this by calling:
// ytgame?.system.getLanguage();
```
### Audio
Your game should also query the YouTube Playables SDK to know if it should play audio, or not:
```js
// If audio is enabled in the YouTube Player then enable it our game too.
// You can also call: ytgame.system.isAudioEnabled()
if (YouTubePlayables.isAudioEnabled())
{
this.enableAudio();
}
else
{
this.disableAudio();
}
// We will also respond to the YouTube Player muting / unmuting the audio.
// You can also call: ytgame.system.onAudioEnabledChange(callback)
YouTubePlayables.setAudioChangeCallback((enabled) => {
if (enabled)
{
this.enableAudio();
}
else
{
this.disableAudio();
}
});
```
You can globally mute and unmute all audio in Phaser by simply doing this:
```js
enableAudio ()
{
this.sound.setMute(false);
}
disableAudio ()
{
this.sound.setMute(true);
}
```
### Save Score and Save Data
After the Game has played, in the `GameOver.js` Scene, we send our final score to YouTube Playables:
```js
// Send the score to YouTube
YouTubePlayables.sendScore(this.registry.get('score'));
// you can also do:
// ytgame?.engagement.sendScore({ value: this.registry.get('score') });
```
We also save our game data, too. This can be any shallow well-formed JS object:
```js
const gameData = {
// game data goes here
};
// Save the data to YouTube
YouTubePlayables.saveData(gameData);
// you can also do:
// ytgame?.game.saveData(string);
```
If using the SDK directly, please note you need to format your data as a valid UTF-16 string with no lone surrogates. Our wrapper will perform these checks for you, but you can use the code in our 'saveData' function to do the same thing, if you'd rather use the SDK directly.
## Handling Assets
Vite supports loading assets via JavaScript module `import` statements.
This template provides support for both embedding assets and also loading them from a static folder. To embed an asset, you can import it at the top of the JavaScript file you are using it in:
```js
import logoImg from './assets/logo.png'
```
To load static files such as audio files, videos, etc place them into the `public/assets` folder. Then you can use this path in the Loader calls within Phaser:
```js
preload ()
{
// This is an example of an imported bundled image.
// Remember to import it at the top of this file
this.load.image('logo', logoImg);
// This is an example of loading a static image
// from the public/assets folder:
this.load.image('background', 'assets/bg.png');
}
```
When you issue the `npm run build` command, all static assets are automatically copied to the `dist/assets` folder.
## Deploying to Production
After you run the `npm run build` command, your code will be built into a single bundle and saved to the `dist` folder, along with any other assets your project imported, or stored in the public assets folder.
In order to deploy your game, you will need to upload *all* of the contents of the `dist` folder to a public facing web server.
## Customizing the Template
### Vite
If you want to customize your build, such as adding a plugin (i.e. for loading CSS or fonts), you can modify the `vite/config.*.mjs` file for cross-project changes, or you can modify and/or create new configuration files and target them in specific npm tasks inside of `package.json`. Please see the [Vite documentation](https://vitejs.dev/) for more information.
## Join the Phaser Community!
We love to see what developers like you create with Phaser! It really motivates us to keep improving. So please join our community and show-off your work 😄
**Visit:** The [Phaser website](https://phaser.io) and follow on [Phaser Twitter](https://twitter.com/phaser_)<br />
**Play:** Some of the amazing games [#madewithphaser](https://twitter.com/search?q=%23madewithphaser&src=typed_query&f=live)<br />
**Learn:** [API Docs](https://newdocs.phaser.io), [Support Forum](https://phaser.discourse.group/) and [StackOverflow](https://stackoverflow.com/questions/tagged/phaser-framework)<br />
**Discord:** Join us on [Discord](https://discord.gg/phaser)<br />
**Code:** 5000+ [Examples](https://phaser.io/examples)<br />
**Read:** The [Phaser World](https://phaser.world) Newsletter<br />
Created by [Phaser Studio](mailto:[email protected]). Powered by coffee, anime, pixels and love.
The Phaser logo and characters are © 2011 - 2024 Phaser Studio Inc.
All rights reserved.
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

template-vite
A Phaser 3 project template that uses Vite for bundling
Vite · 游戏站

vite-phaser-ts
Vite + Phaser + Typescript starter template.
Vite · 游戏站

phaser-editor-template-solid
A Phaser Editor 4 project template that combines SolidJS, TypeScript and uses Vite for bundling
SolidJS · 游戏站

2048
2048 是一个风靡全球的数字合并益智游戏的开源网页实现,最初由 Gabriele Cirulli 开发,基于 1024 和 Saming 的 2048 克隆而来。
JavaScript · 游戏站

flexboxfroggy
Flexbox Froggy 是一个通过游戏化方式学习 CSS Flexbox 的开源项目,由 Thomas Park 创建并维护。
JavaScript · 游戏站

server survival
Server Survival 是一个将云架构知识融入游戏机制的 3D 模拟项目。 你扮演云架构师,通过搭建和扩展基础设施来应对流量增长、DDoS 攻击与预算限制。
Three.js · 游戏站
