Play module files in your kha project!
Supported targets:
- Native (C++) : requires libopenmpt & requires Kore MPT
- HTML5: requires Chiptune2
Clone this repo under
project/Libraries/
-
Build your project at least once so the build folders are created.
-
Copy/Clone the repository where ever you like.
-
Copy the files
. chiptune2.js . libopenempt.js . libopenmpt.js.mem
To the root of the folder of your html5 build where the index.html resides:
project/build/html5-debug or project/build/html5
-
edit the index.html to include the scripts
<body> <canvas id="khanvas" width="0" height="0"></canvas> <script src="kha.js"></script> <script src="libopenmpt.js"></script> <script src="chiptune2.js"></script> </body>
-
Clone KoreMPT and add it to your project under Libraries.
-
In the korempt folder create a folder names LibOpenMPT
-
Download libopenmpt and unzip it under the previously created folder The folder structures should look like
project/Libraries/korempt/LibOpebMPT/common/ project/Libraries/korempt/LibOpenMPT/libopenmpt/ project/Libraries/korempt/LibOpenMPT/include/
-
Add the lib to your khafile.js
project.addLibrary('korempt');
import kha.modplayer.ModulePlayer;
class myClass{
var mod:ModulePlayer;
//somewhere in your code
mod = new ModulePlayer();
mod.init();
mod.setFile(kha.Assets.blobs.mod_file);
mod.setVolume(1.0);
mod.play();
}
For kore/c++ targets it's important that ModulePlayer object is defined in class scope as a member variable in haxe. Creating it as a local variable ( i.e. in a function ) means the object is deleted once it goes out of scope.