maybe the only problem with NME is the lack of documentation and not so active community outside the forum and mailing list. there's still so many things not covered in the tutorial and some googling of NME-Android related things won't give you direct answer to the problem. stackoverflow tag of haxe/nme tag doesn't have so much question and reddit r/haxe sub just have a small number of reader.
One problem stuck me now is integration of ads, specifically Chartboost . Chartboost is a really good ads network with a high CPM. before using NME I used libgdx to create android games, and chartboost integration with libgdx is easy as breeze because it's covered on the tutorial.
I searched everywhere looking for how to integrate chartboost (Android) on NME and it result on nothing. Luckily, after struggling so much with so many different keyword I stumbled upon gigglingcorpse's blog post and found some answer. I contacted gigglingcorpse and after consulting for a while finally I could integrate the ads! Big Thanks!
I feel the urge to write this tutorial to help others give more understanding about of how to integrate chartboost (Android) with NME. It's not really hard but maybe it could confuse new player which still not understand about how NME work behind the screen.
So let's start!
First thing first! In order to integrate chartboost ads in our game we need to first register the app inside chartboost dashboard. just register on chartboost and Add App to get the APP_KEY and SIGNATURE. I won't tell you how to do that here. just look it up on the official help yourself. just make sure the test mode enabled . also you need to create campaign and check the created app so the app could display ads inside.
After we got the APP_ID and APP_SIGNATURE we can integrate it in our NME project.
I used FlashDevelop in this tutorial so I will create a HelloWorld project for the purpose of tutorial.
First thing to do is adding chartboost library to the project. in order to do that we need to create libs folder inside assets folder so the structure will be like assets/libs. Download the chartboost android library from the official download and then copy it to libs folder .
|add chartboost library|
Then on the application.nmml write a template tag to rename it as lib folder in android
Adding chartboost library is done! Next step is putting the code.
Chartboost integration require us to add some code on Activiy class in Android. So we need to override the default MainActivity.java emplate. MainActivity.java s an android class generated by haxe as the Activity class to launch in android. the default MainActivity.java will looks like a blank class as seen below
We cannot add code directly to the generated MainActivity.java class because the code added will be wiped out when we do the next build. In order to override the MainActivity.java class we need to change the MainActivity.java template and fill it with necessary code. To do that , copy MainActivity.java template from nme installation folder. The template located in templates\default\android . copy the MainActivity template to project directory and then register it as template on application.nmml . change the [package_path] with your app package path
Open MainActivity.java and add the code as instructed on the official tutorial . there's nothing need to be changed once you got it done so you can just copy paste code below to your MainActivity.java .just remember to change "YOUR_APP_ID" and "YOUR_APP_SIGNATURE" with the APP_ID and APP_SIGNATURE.
we could also use the code above as a template for next project without changing much of the code, just the APP_ID and APP_SIGNATURE.
save up the change and.... test run it on android.
|Voila! Chartboost (Android) with HaxeNME|
to give more control of the ads showing , you could change the showInterstitial() method with cacheInterstitial() in onCreate() and then call cb.showInterstitial() through JNI call from haxe. for convenience I created a public static method called showChartboost() in MainActivity.java and call it from haxe like below
there.. from here on much can be done via JNI so I'll leave it up to you about the advanced things. thanks for reading!
~End of Tutorial~