A starter template for Phaser 3 with TypeScript and webpack for building excellent html5-games that work great in the browser and on mobile devices.
Key Features • Preview • How To Use • React controls • Websocket support • Credits
- All newest ES 2020 features
- Prettier
- Webpack dev server
- Includes Phaser 3 TypeScript typings
- For development and production builds
- React gui development
- Websocket integration
This is what you get after installing this template. A simple and clean starter template written in TypeScript.
To clone and run this template, you'll need Git and Node.js (which comes with npm) installed on your computer. From your command line:
# Clone this repository (yes, npx not npm)
$ git clone https://github.com/tfkfan/phaser3-react-template.git
# Go into the repository
$ cd phaser3-react-template
# Install dependencies
$ npm install
# Start the local development server (on port 8080)
$ npm start
# Ready for production?
# Build the production ready code to the /dist folder
$ npm run build
This template allows to use react hooks outside of react components
To use this take a look to /src/global-state.ts file to create your own handlers
To register new handler write inside your React functional component:
const [fps, setFps] = useState(0);
const [version, setVersion] = useState('');
useGlobalReg({
setVersion,
setFps
});
To use it inside phaser game:
useGlobalState(state => state.setVersion(`Phaser v${Phaser.VERSION}`));
Use GameWebSocket class to communicate with ws server...
First, initialize websocket to communicate with specific server host:
webSocket.initConnection("<your ws host>")
Then use functionality directly:
webSocket.on(MessageType.UPDATE, data => {
}, this)
webSocket.send(MessageType.PLAYER_KEY_DOWN, {inputId: 'RIGHT', state: false});
A huge thank you to Rich @photonstorm for creating Phaser