Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Kha supports multiple workflows:
Using Kode Studio is the easiest way of getting started with Kha, followed by the haxelib workflow. Using git is more robust and recommended when starting an actual project with Kha.
To get started with Kha and Kode Studio, download the build supported by your operating system:
From within Kode Studio, open an empty directory on your file system. Press
F1 to open the VSCode command palette, then search for and execute
Init Kha Project. A project template should now be set up in your project directory.
To build and run the project hit
F5. If everything was set up correctly in the previous steps an empty black window should open up. Congratulations, you have just built your first Kha project! The result should be located in the
build directory at the root of your project folder. Kode Studio contains two debuggers, an HTML5 based debugger which is used by default and the Krom debugger which is more advanced but not yet as stable. You can switch the debugger in the debug panel which you can select on the left side. To build for any other target hit
Ctrl+Shift+B which brings up a list of the available targets. You can also change which target is used for code completion via a small drop down menu at the bottom of the window (HTML5 is selected by default).
The version of Kha used by Kode Studio is located in
[Kode Studio]/resources/app/extensions/kha/Kha. However, Kode Studio can be configured to use a different one. This is done by opening up Kode Studio user settings (
File > Preferences > User Settings > Extensions > Kha configuration) and setting the
Kha Path to the path of your desired Kha library version.
To create a new Kha project run
node /path/to/Kha/make --init inside of an empty directory. Now you can create some project files using for example
node /path/to/Kha/make (which will create a project for the system you're currently running) or
node /path/to/Kha/make html5 (html5 projects compile and run very fast). Project files are by default created inside of a build subdirectory.
When using Windows and the Direct3D9 backend (by default it uses a Direct3D11 backend) you will eventually have to install Microsoft's dxwebsetup.exe. This is included in Kha's Kore/Tools/krafix subdirectory.
You can get a copy of NodeJS on its site here and install it.
If you have NodeJS already installed make sure it's updated! You can do so with the following commands.
sudo npm cache clean -f node --version sudo npm install -g n sudo npm stable node --version
Starting with Kha
Kha projects are usually handled using git submodules so that every dependency is properly versioned. Even the Haxe compiler itself is just a submodule.
If you want to add Kha as a submodule for your git project just use
git submodule add https://github.com/Kode/Kha git submodule update --init --recursive
You can also clone the Empty project and start from it - but make sure to update Kha afterwards (see below).
git clone --recursive https://github.com/Kha-Samples/Empty.git
Using Kha from one place
If you want to use only one clone of the Kha repository for all of your projects, you can clone Kha in a place in your system, and use this path when use Kha, like
node <kha-path>/make. To get things easier, create a batch file or script with the complete command.
In Windows, this can be a .bat file on the windows folder with this:
@echo off node <kha-path>\make %*
Or on linux, a shell script:
#!/bin/bash node /<kha-path>/make $@
If you want to update the Kha submodules in your repository you can do it with just this command!
git submodule foreach --recursive git pull origin master
If you are using Kha from a separate place, use the above command in your Kha directory, and after this use this command to update Kha itself:
git pull origin master
otherwise only the submodules of Kha would be updated.
These are steps on using Kha from one directory & then pointing to it within Kode Studio. So we can use the most up to date version of Kha
- Install NodeJS (this is optional and only required if you want to use Kha from the command line)
- Choose a location where you want Kha to install. This can be either somewhere public or kept hidden but the location needs to be writeable.
- Point your command line/terminal to your chosen folder
- Input this:
git clone --recursive https://github.com/Kode/Kha.git
- Within Kode Studio, go to
Preferences > Settings
- Type in the path to where Kha has been installed. Example:
Kode Studio will from now on use your manually downloaded version of Kha which you can keep up to date via the method described in the Updating Kha section above.