Workshop info: Haxe Tutorial
This is an agar.io clone to demonstrate the capability of Haxe in building cross platform games, where codes are shared among multiple game platforms (web, mac, windows, android & ios), as well as between game client and game server for multiplayer games.
Demo: https://kevinresol.github.io/hkoscon2017-haxe-game/ (single player mode)
Participants should have programming experience with at least one programming language. Proficiency with JavaScript, Java, or C# is ideal, but experience with other languages such as C/C++, Python, or Ruby is also sufficient. Participants should have some familiarity using the command line. Participants should bring their own laptop computer, with either Windows, Mac, or Linux installed.
Please follow the instruction listed below before the workshop, such that you can progress smoothly.
Get Haxe from https://haxe.org/download/.
Get Node.js from https://nodejs.org/, and optionally yarn.
Get Git and make it available in the command line. i.e. git --version
should print something like git version 2.7.4
.
Note: if it is the first time you are using haxelib
, you will have to run haxelib setup
first.
-
OpenFL. According to the instruction at http://www.openfl.org/learn/docs/getting-started/:
haxelib install openfl haxelib run openfl setup
-
haxelib install haxe-ws
-
haxelib install hxnodejs
-
haxelib install hxcpp 3.4.64
Although in theory you can use any IDE or text editor, we recommend using Visual Studio Code with the Haxe Extension Pack, which offers the best Haxe support at the moment.
(Optional, for building native targets, e.g. mac, windows, linux, ios, android) Depending on your OS, Visual Studio (Windows), XCode (Mac), or gcc (Linux).
We will introduce Haxe and go through creating a simple multi-player game during the workshop together. The instruction will be given during the workshop. Below are some notes for future reference.
The workshop is divided into 6 sections:
- Getting started
- what is Haxe
- showcases
- download and install
- Haxe programming basics
- VSCode project setup
- basic building blocks
- Game building with OpenFL
- using Haxe libraries and frameworks
- game architecture
- Using NodeJS
- using native libraries (writing externs)
- NodeJS basics (CLI, NPM)
- Multiplayer
- server-client communication
- Where to go from here
- Haxe social networks
- pointers to advanced topics: game engines, hxcpp externs, web development, macros
Each section is 30-minute long, with 10-minute breaks in-between.
- Haxe Manual: https://haxe.org/manual/introduction.html
- Haxe API docs: https://devdocs.io/ (or http://api.haxe.org/)
- Try Haxe: https://try.haxe.org/
- OpenFL tutorials: http://www.openfl.org/learn/tutorials/
- OpenFL API docs: http://api.openfl.org/
haxe-ws
library: https://lib.haxe.org/p/haxe-wsws
npm package: https://www.npmjs.com/package/ws#usage-examples
The World
class contains the core game logic.
When the game is set to single-player mode, the World
is run in the client.
In other words, the same piece of Haxe code for the World
class is compiled into different platforms
(web, mac, windows, android & ios).
When the game is in multi-player mode, the World
is run on the server. Again, the same piece of
Haxe code for the World
class is compiled into the server language (nodejs for our choice here).
The Command
and Message
enums represents the protocol between the client and server in multiplayer
mode. The same piece of code is used in both client and server.
Feel free to open issues or contact us directly.
To the extent possible under law,
Andy Li & Kevin Leung
has waived all copyright and related or neighboring rights to
Haxe Summit 2017 Haxe Tutorial.
This work is published from:
Hong Kong.