Skip to content

Managing Your Assets

BitsAtPlayDev edited this page Sep 19, 2016 · 20 revisions

Include your assets

To use assets in kha first you need to include them into your project (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 project, is to transform your assets into more optimize format depending on your target. So for example if you add a .wav in your assets folder and you want to build for windows or mac, khamake 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, jpg, hdr
  • Sounds: wav (sample rate:44100Hz 16 bit)
  • Videos: mp4

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

Loading your assets

Before 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 recommended if you don't 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