Update: People that work on OpenFL explained how to create an extension here it’s better if you read that instead.
Basically I wanted to write about what I did with Fluff Eaters and Collow here because sometimes it’s difficult to understand how things work, even if you google a lot, sometimes there is nothing or documentation is very scarse.
OpenFL is a great library, I think it’s what I wanted to use when I decided to create 2D games for mobile (and many other platforms) but if you don’t have experience working with it or with AS3/Flash (which I did not have), it’s difficult to understand sometimes.
So I want to start my posts about OpenFL/Haxe/Gamedev with something I accomplished recently: How to create an extension for Lime/Haxelib, specifically for using OpenFL but I guess you can use it with anything else if you want.
This particular topic is something you probably won’t need but if you want to make a library for your game, an extension, something that could be reusable for different projects, it’s important to understand how to do it.
First of all, open the console and go to the folder you want the extension to be in. Once you are there, type the following command:
haxelib create extension <name of your extension>Note: Andy Li (@andy_li) noticed I made a mistake writing the command here and he kindly pointed it out, it should be:
lime create extension <name of your extension>
Where, <name of your extension> is the name you want to give to your new extension.
Once you do this, haxelib lime will automatically create a folder with the name you put there and it contains the whole structure to make your library work. It will create:
- A file <name of your extension>.hx which you can use to link to native code or create whatever you want to create
- A folder of dependencies called “dependencies” which contains native code for your extension, in my case, I created an extension that will be used on Android and probably iOS too (haven’t tried this yet) that will be located on that folder too
- An “include.xml” file which will tell Haxe about your extension, where the dependencies are located their name.
- Other folders and files I will not explain here
You can check an old NME post about how to create an extension in case you want to understand it better. I believe that the proper way (currently) to do it is to use the haxelib lime create extension command because it automatically creates all the proper templates for you and you won’t have to worry about that but you always can do it manually.
While you are working on your extension you probably will want to test it on a a different project or probably publish it somewhere. I’m not sure if this is the proper way to do what I’m going to explain but for me makes sense so I’m going to explain it and explain why, if you have a better way, please let me know.
I have one project called “my-game” and an extension I’m creating “my-extension”, in order to include my-extension in “my-game”, you will do it as you include any other extension, you go to your project “my-game”, search for “application.xml” and add the following line:
<haxelib name=”my-extension” />
Of course haxelib doesn’t know yet that your extension is there, so you have to link it somehow. To do that, if you are working locally, go to the console and type this:
haxelib dev <name of your extension> <path to your extension>
In the case for our example, it would be:
haxelib dev my-extension whatever-path-you-created-your-extension
If you want to test if the extesion was properly installed, type this:
haxelib list
And you should see your extension there, pointing to the path you added.
If you want your extension from a git repository (which is useful for sharing and keeping proper track of your code and good practice, etc, etc), do this:
haxelib git <name of your extension> <git repository url>
If everything went well, you can compile “my-game” and it should compile without errors. Now, all the methods you create for your extension will be available to use from your project.
The sample that haxelib lime creates automatically contains some code for adding native Android code (in Java), if you want to create an extension that uses Android, you can use that, maybe, if somebody is interested, I will explain how I made the extension for Google Play, which is not complete yet but finally it’s working as expected.
Finally if you need extra documentation on the haxelib commands:
haxelib help
To understand all this I searched a lot on the internet, I want you to take a look at the sources that helped me with this:
This guy here has a good approach on making libraries that use Google Play library as their base, I’m actually basing my own Google Play Game Services extension on his approach because I believe is good. However, it wasn’t easy to understand what he did without wasting a lot of time reading code and analysing it, once the extension is complete maybe I’ll talk about this.
Here another interesting repository that has different extesnions and their code, some of them are outdated and that’s one of the reasons I decided to create a new one.
Haxe->Haxelib website: http://haxe.org/manual/haxelib.html
I did not decided to make a new Google Play Services extension because I like re-making things, before that I searched a lot to find a good extension, I did find those two I mentioned before but, one of them is outdated and the other one does not work properly with the admob’s extension I wanted to use.
I got many good things from this:
- A library that is working
- A library up to date
- Understanding about making new libraries
- The opportunity to create better and new libraries
- Create some documentation and share with others
So I think this is it, if there is anything that was not clear, you have a better way to do it or you have questions, feel free to ask me.
Leave a Reply
You must be logged in to post a comment.