Hello World
installed both Heaps and Visual Studio Code, let’s create a new Heaps application.
Concepts
compile.hxmlfile to tell it what to compile, how and where to compile it, and which libraries to include.main. -.├── .vscode/│ └── launch.json├── res/├── src/│ └── Main.hx└── compile.hxml
Create your project
helloHeapscompile.hxml--cp src-lib heaps-js hello.js-main Main-debug
-cp srcTells haxe where to search for your code files-lib heapsTells haxe to import the heaps library-js hello.jsTells haxe to compile to javascript in the project directory-main MainTells haxe that Main.hx is your entry point-debug Tellshaxe to run in debug modehello.jsoutput, and that our main class should beMain.hxfile.-debugfile allows generation of source maps in order to be able to debug your JS application.Open with VSCode
helloHeapsfolder with VSCode by launching VSCode and navigating the main menuFile > Open FolderCreate Hello World example
Main.hxin asrcfolder in your project directory and put the following contentclass Main extends hxd.App { override function init() { var tf = new h2d.Text(hxd.res.DefaultFont.get(), s2d); tf.text = "Hello World !"; } static function main() { new Main(); }}
s2dand set its text.Compile and run Output
To be able to compile and debug your application directly from vscode, you need to create a launch task..vscodedirectory in your project folder and create a new file calledlaunch.json. Add the following code to the file:{ "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "Launch Chrome against localhost", "url": "file://${workspaceFolder}/index.html", "webRoot": "${workspaceFolder}", "preLaunchTask": { "type" : "haxe", "args" : "active configuration" } } ]}
index.htmland add the following code to it:<!DOCTYPE><html><head> <meta charset="utf-8"/> <title>Hello Heaps</title> <style> body { margin:0;padding:0;background-color:black; } canvas#webgl { width:100%;height:100%; } </style></head><body> <canvas id="webgl"></canvas> <script type="text/javascript" src="hello.js"></script></body></html>
F5, the project will compile and run.Ctrl-Shift-Band selecthaxe : active configurationhello.jsandhello.js.mapfiles created in your project folder:Debugging
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.
