-
-
Notifications
You must be signed in to change notification settings - Fork 168
Embedding Assets Within Built Applications
Kha can embed assets, such as images, sound, JSON & XML data, amongst other formats into a compiled application. This then puts the data inside the compiled application, rather than being out in the open once built.
You do need to input a few different things & even change your way you would load assets. Its not too hard, but is understandable.
Instead of having the standard project.addAssets('Assets/**');
[which loads everything in that Assets
folder, you would swap it out for several of these, depending on what it is you want to hide:
project.addParameter('-resource ../location/to/your/file.json@filejson');
This only accesses 1 file called file.json
, & will be called up in your project using filejson
.
Also bear in mind, that when we comment out the original project.addAssets('Assets/**');
, that now knocks out our ability to access any other assets we may have had in it & have not put into its own addParameter();
.
A work-around we can do if we wanted access to things like images, or sound [which can be seen when compiled], but want to hide our file.json
, is something like this.
project.addAssets('Assets/audio/**');
project.addAssets('Assets/texture/**');
The audio path only has audio files in, much like the texture path only has images in, but we are saying where these live.
It's different than what we could normally do such as:
var jsonData = haxe.Json.parse(Assets.blobs.get('file_json').toString());
trace(jsonData);
We would need to use some of Haxe's own useful classes to help us. But its not that hard.
var jsonData = haxe.Json.parse(haxe.Resource.getString('filejson'));
trace(jsonData);
Remember, that filejson
is what we had named in our khafile.js
:
project.addParameter('-resource ../location/to/your/file.json@filejson');
There is further information on -resource
, via the Haxe manual here
- Introduction
- Getting Started
- Breaking Changes
- FAQ
- System targets
- Graphics targets
- Documentation
- API package descriptions