Google AdMob extension for OpenFL applications. Working on both Android and iOS. Code is heavily based on NMEX extension which is pretty much outdated right now.
Thanks
This is a fork of the admob-openfl library from Michał Korman. All credits go to Michał and whomever pushed to that project.
Changes
For our projected we needed a fast performing ad-library, since we would show and hide the ads on every dead/win of our game. The original implementation created a view on Ad.show()
and destroyed it again on Ad.hide()
. This, in our case, led to a buildup of views being created and destroyed, which made our game drop from 60FPS to 10FPS within minutes. To circumvent this issue we do not recreate views, but only show and hide them. Notice: this means that the ad is not refreshed every Ad.show()
call!
We only changed the banner ads implementation
Original statement
- Clone this repo using
haxelib git admob https://github.com/mkorman9/admob-openfl
command - Include extension to your project
<haxelib name="admob" />
- Import AD class
import admob.AD;
- Setup ads at the beginning of your code
AD.init(ADMOB_ID, AD.LEFT, AD.BOTTOM, AD.BANNER_PORTRAIT, false);
where arguments are following:
- Ad unit id.
- Position in x axis. Could be
AD.LEFT
orAD.RIGHT
- Position in y axis. Could be
AD.TOP
orAD.BOTTOM
- Banner size. Could be
AD.BANNER_PORTRAIT
orAD.BANNER_LANDSCAPE
(see google's documentation) - Test mode. Whether enable test ads or not. Default value is false.
- Show banner
AD.show();
- You can hide it anytime by calling
AD.hide();
Prerequisites on iOS
- Add following code to your project.xml
<ios linker-flags="-force_load __PATH_TO_THE_HAXELIB_DIR__/admob/git/ndll/iPhone/libGoogleAdMobAds.a" />
don't forget to replace __PATH_TO_THE_HAXELIB_DIR__
with real path to your haxelib, in most cases it will be /usr/lib/haxe/lib
- After creating XCode project, drag libGoogleAdMobAds.a to Project Settings->Build Phases->Link with binaries
- (Optional) You can rebuild binaries on Mac OSX using five simple commands:
cd __PATH_TO_THE_HAXELIB_DIR__/admob/git/project
haxelib run hxcpp Build.xml -Diphoneos
haxelib run hxcpp Build.xml -Diphoneos -DHXCPP_ARMV7
haxelib run hxcpp Build.xml -Diphonesim
haxelib run hxcpp Build.xml
Prerequisites on Android
- Copy android-template directory to your project
- Add following code to your project.xml:
<java path="android-template/libs/google-play-services.jar" if="android" />
<template path="android-template/AndroidManifest.xml" rename="AndroidManifest.xml" if="android" />
<template path="android-template/src/org/haxe/lime/GameActivity.java" rename="src/org/haxe/lime/GameActivity.java" if="android" />