Skip to content

Commit 0ad3cc6

Browse files
Merge pull request #2 from devshareacademy/pipeline-migration
phaser 4 shader examples
2 parents 1f8e9fd + fc164cb commit 0ad3cc6

File tree

22 files changed

+2206
-0
lines changed

22 files changed

+2206
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dist
2+
/node_modules
3+
yarn-error.log
4+
.DS_Store
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"eslint.format.enable": true,
3+
"eslint.options": {
4+
"overrideConfigFile": "config/.eslintrc"
5+
},
6+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
7+
"editor.codeActionsOnSave": {
8+
"source.fixAll.eslint": "explicit"
9+
},
10+
"cSpell.words": [
11+
"devshareacademy",
12+
"mediump",
13+
"tweakpane"
14+
]
15+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Phaser 4 TypeScript - Shader Examples
2+
3+
Contains example code of how to use various shaders in Phaser 4. This is the sample code that I shared in my tutorial video hosted on YouTube here were we walk through migrating some existing Phaser 3 shaders to the Phaser 4:
4+
5+
[<img src="https://i.ytimg.com/vi/4Dj5PSKwjak/hqdefault.jpg">](https://youtu.be/4Dj5PSKwjak "Phaser 3 Tutorial: Getting Started with Shaders!")
6+
7+
You can see a live demo of the examples here: <a href="https://devshareacademy.github.io/phaser-4-typescript-games-and-examples/examples/rc5/shader-pipeline-migration/index.html" target="_blank">Shader Examples</a>.
8+
9+
While viewing the examples, if you press the `space` key, you can navigate between various examples. Below is a list of the examples shaders that can be seen and the corresponding files to that example:
10+
11+
| Example | Description | Location |
12+
|---------|-------------|----------|
13+
| Grey Scale | Example of how to apply a grey scale affect to all pixels. | `./src/shaders/grey-scale-shader.ts` |
14+
| Screen Wipe | Example of how to use custom variables in a shader to create animations, like a scene transition. | `./src/shaders/wipe-shader.ts` |
15+
| Noise Mix | Example of how to pass an addition texture to a shader and mix this texture with the original texture. Used to create a grainy effect. | `./src/shaders/noise-shader.ts` |
16+
17+
![Shader Examples 1](./docs/example.gif?raw=true)
18+
19+
![Shader Examples 2](./docs/example2.gif?raw=true)
20+
21+
## Local Development
22+
23+
### Requirements
24+
25+
<a href="https://nodejs.org" target="_blank">Node.js</a> and <a href="https://pnpm.io/" target="_blank">PnPm</a> are required to install dependencies and run scripts via `pnpm`.
26+
27+
<a href="https://vitejs.dev/" target="_blank">Vite</a> is required to bundle and serve the web application. This is included as part of the projects dev dependencies.
28+
29+
### Available Commands
30+
31+
| Command | Description |
32+
|---------|-------------|
33+
| `pnpm install --frozen-lockfile` | Install project dependencies |
34+
| `pnpm start` | Build project and open web server running project |
35+
| `pnpm build` | Builds code bundle for production |
36+
| `pnpm lint` | Uses ESLint to lint code |
37+
38+
### Writing Code
39+
40+
After cloning the repo, run `pnpm install --frozen-lockfile` from your project directory. Then, you can start the local development
41+
server by running `pnpm start`.
42+
43+
After starting the development server with `pnpm start`, you can edit any files in the `src` folder
44+
and parcel will automatically recompile and reload your server (available at `http://localhost:8080`
45+
by default).
46+
47+
### Deploying Code
48+
49+
After you run the `pnpm build` command, your code will be built into a single bundle located at
50+
`dist/*` along with any other assets you project depended.
51+
52+
If you put the contents of the `dist` folder in a publicly-accessible location (say something like `http://myserver.com`),
53+
you should be able to open `http://myserver.com/index.html` and play your game.
54+
55+
### Static Assets
56+
57+
Any static assets like images or audio files should be placed in the `public` folder. It'll then be served at `http://localhost:8080/path-to-file-your-file/file-name.file-type`.
58+
59+
## Credits
60+
61+
The assets used in this demo were made from free assets that were created from the following artists: <a href="https://axulart.itch.io/" target="_blank">ansimuz</a>.
62+
63+
List of assets:
64+
65+
* <a href="https://axulart.itch.io/axularts-basicplains-tileset-ver2" target="_blank">Basic Plains Set</a>
66+
* <a href="https://axulart.itch.io/small-8-direction-characters" target="_blank">Character</a>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"root": true,
3+
"extends": "@devshareacademy/eslint-config",
4+
"parserOptions": {
5+
"project": "./tsconfig.json"
6+
},
7+
"rules": {},
8+
"ignorePatterns": ["node_modules", "dist"]
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vite';
2+
3+
export default defineConfig({
4+
base: "./",
5+
build: {
6+
rollupOptions: {
7+
output: {
8+
entryFileNames: 'assets/js/[name]-[hash].js',
9+
},
10+
},
11+
},
12+
});
9.63 MB
Loading
9.41 MB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<title>Phaser 4 Shader Examples</title>
6+
<style>
7+
html,
8+
body,
9+
.container {
10+
margin: 0px;
11+
height: 100vh;
12+
width: 100vw;
13+
overflow: hidden;
14+
background: #d7d7d7;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div class="container" id="game-container"></div>
20+
<script type="module" src="/src/main.ts"></script>
21+
</body>
22+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "@devshareacademy/phaser-4-shader-examples",
3+
"version": "1.0.0",
4+
"description": "A few shader examples for Phaser 4 that are migrated from Phaser 3.",
5+
"scripts": {
6+
"start": "vite --config config/vite.config.js",
7+
"build": "tsc && vite build --config config/vite.config.js",
8+
"serve": "vite preview --config config/vite.config.js",
9+
"lint": "eslint ./src --ext .ts,.tsx --config ./config/.eslintrc"
10+
},
11+
"author": "scottwestover",
12+
"license": "MIT",
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/devshareacademy/phaser-4-typescript-games-and-examples.git"
16+
},
17+
"homepage": "https://github.com/devshareacademy/phaser-4-typescript-games-and-examples",
18+
"devDependencies": {
19+
"@devshareacademy/eslint-config": "0.0.18",
20+
"@devshareacademy/prettier-config": "0.0.6",
21+
"@devshareacademy/tsconfig": "0.0.3",
22+
"@tweakpane/core": "2.0.3",
23+
"@typescript-eslint/eslint-plugin": "7.1.0",
24+
"@typescript-eslint/parser": "7.1.0",
25+
"eslint": "8.57.0",
26+
"eslint-config-prettier": "9.1.0",
27+
"eslint-plugin-prettier": "5.1.3",
28+
"prettier": "3.2.5",
29+
"typescript": "5.3.3",
30+
"vite": "5.1.4"
31+
},
32+
"dependencies": {
33+
"phaser": "4.0.0-rc.5",
34+
"tweakpane": "4.0.3"
35+
},
36+
"resolutions": {},
37+
"prettier": "@devshareacademy/prettier-config",
38+
"volta": {
39+
"node": "20.11.1",
40+
"yarn": "1.22.11",
41+
"pnpm": "8.15.4"
42+
},
43+
"engines": {
44+
"node": ">=20.11.0",
45+
"npm": ">=10.2.0",
46+
"pnpm": ">=8.15.0"
47+
}
48+
}

0 commit comments

Comments
 (0)