Castle Game Engine has many, easy to use integrations with services for mobile games. While I’m working on my Android game, I’ve made many improvements to the Admob module.
Required App ID
Starting from version 17 of the Ads SDK, Admob requires the application ID (App ID) in AndroidManifest.xml. In the case of CGE engine, this identifier is set in CastleEngineManifest.xml
:
<service name="admob"> <parameter key="app_id" value="..."/> </service>
You can use the ca-app-pub-3940256099942544~3347511713
ID for testing. Remember that using this service requires also google_play_services
.
Rewarded ads
The module supports now rewarded ads. To use them, just set new RewardedUnitId
parameter in TAds.InitializeAdMob
:
procedure TAds.InitializeAdMob(const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string);
If you don’t want to use some form of advertising e.g. interstitial, you can use an empty string in InitializeAdMob
procedure. To display a rewarded advertisement, simply use the ShowFullScreen
procedure with the atReward
ad type:
CGEAds.ShowFullScreenAd(anAdMob, atReward, true);
More accurate result in TAdClosedEvent
The TAdClosedEvent
event has been rebuilt, the Watched
parameter has now TAdWatchStatus
type instead of Boolean
. Possible values and their meaning are given in the table below:
TAdWatchStatus | AdMob errorCode equivalent | Description |
wsWatched | – | The ad was displayed. |
wsUnknownError | ERROR_CODE_INTERNAL_ERROR | Ad mob internal error or unknown error code. |
wsNetworkNotAvailable | ERROR_CODE_NETWORK_ERROR | No internet connection. |
wsNoAdsAvailable | ERROR_CODE_NO_FILL | No ads available. |
wsUserAborted | – | Rewarded ad aborted by user. |
wsAdNotReady | – | The ad is still loading (when we don’t want to wait). |
wsAdNetworkNotInitialized | – | Ad network not initialized or request for uninitialized ad type. |
wsInvalidRequest | ERROR_CODE_INVALID_REQUEST | Invalid Request – bad Unit ID for example. |
wsApplicationReinitialized | – | Java application was killed, but native code survived, while waiting for ad to finish. |
Debug
If you want more logs, change the value of the ServiceAdMob.debug
from false
to true
. Service source file is located in: tools/build-tool/data/android/integrated-services/admob/app/src/main/java/net/sourceforge/castleengine/ServiceAdMob.java
How to get it?
The changes have been merged and are available in the master branch on github.