Skip to content

Managing Your Assets

juakob edited this page Aug 17, 2016 · 20 revisions

Include your assets

To use assets in kha first you need to include them into your proyect(khafile.js) so khamake can find them during the build stage. By default the folder Assets is created and linked in khafile.js, but you can add other folders by adding project.addAssets('OtherAssetFolder/**'); in your khafiles.js.

khamake

one of the responsibilities of khamake beside building your proyect, is to transform your assets into more optimize format depending on your target. So for example you add a .wav in your assets folder and you want to build to windows or mac it will generate a .ogg file. If you target html5 and add the --mpeg command (node Kha/make html5--ffmpeg "/path/to/ffmpeg.exe need the .exe) it will generate a .mp4 or in flash a .mp3. The same analogy works for image files.

Expected formats

khamake expects the assets to be in this formats:

  • Images: png
  • Sound: wav
  • Video: ?

Any other format will not be change and will be available in your code through Assets.blobs as Bytes.

Loading your assets

Befoure you can use an asset you need to load it into memory, to do so you need to use one of the loading method under the class Assets. If you want to load everything you can call loadEverything, but its only recomended if you dont use many assets, otherwise you will fill your memory.

Using the assets in your code

To use your assets after they are loaded into memory, you just need to call Assets..nameOfAsset.

Add more assets

Every time you add more assets you need to call make command. ##Assets names The names shown in Assets are loaded using a macro and a json file in the "-resources" folder, so all assets names must respect variable/function naming rules.

Clone this wiki locally