Getting Started

Robert Konrad edited this page Sep 27, 2018 · 42 revisions

Getting Started

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.

Kode Studio

Kode Studio is a fork of Visual Studio Code. It is a portable cross-platform IDE optimized for Kha development that comes bundled with a version of Kha and useful extensions. It features debugging support based on VSCode's Chrome debugger, Haxe's JavaScript target, and a modified Kha HTML5 target.

To get started with Kha and Kode Studio, download the build supported by your operating system:

Download Kode Studio

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 use Kha's git based workflow you need git and node (v8.9+).

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.

Installing NodeJS

You can get a copy of NodeJS on its site here and install it.

Update NodeJS

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
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

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:

node /<kha-path>/make $@

Updating Kha

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.

Quick Setup

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
  • Within Kode Studio, go to Preferences > Settings
  • Type in the path to where Kha has been installed. Example:
"kha.khaPath": "/my/path/to/kha"

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.