Hello World
- Heaps uses a file to tell it what to compile, how and where to compile it, and which libraries to include.
- The entry point of a Haxe program is a class containing a static function called
main
. - A simple heaps directory structure will look like this:
Create your project
- Create a new directory named
helloHeaps
- Create a new file called
compile.hxml
-cp src
Tells haxe where to search for your code files-lib heaps
Tells haxe to import the heaps library-js hello.js
Tells haxe to compile to javascript in the project directory-main Main
Tells haxe that Main.hx is your entry point- haxe to run in debug mode
This will tell the compiler that we are using the library Heaps, that we will compile to JavaScript hello.js
output, and that our main class should be Main.hx
file.
The -debug
file allows generation of source maps in order to be able to debug your JS application.
At this point, you can open the helloHeaps
folder with VSCode by launching VSCode and navigating the main menu File > Open Folder
Create Hello World example
Create a new Main.hx
in a src
folder in your project directory and put the following content
This example creates a Heaps Text component, adds it to the 2D scene and set its text.
If it does not already exist, create a .vscode
directory in your project folder and create a new file called launch.json
.
Add the following code to the file:
Now, in your project directory, create a file index.html
and add the following code to it:
Now, by hitting F5
, the project will compile and run.
If everything works well, you should now have both hello.js
and files created in your project folder:
Debugging
In order to Run with Chrome, you need Chrome Debugger VSCode extension. Open again the Extension manager and search for Chrome to install it:
You can put breakpoints into your Heaps application by clicking in the margin to left to the line number in your source code. You can then start again the problem and see it break at the desired position.