On this page
  1. Interstitial
    1. request_interstitial
    2. is_interstitial_loaded
    3. show_interstitial
  2. Rewarded
    1. request_rewarded
    2. is_rewarded_loaded
    3. show_rewarded
    4. take_reward_earned
    5. reward_amount

rmp::ads

namespace #include <rmp/ads.h>

rmp::ads — interstitial and rewarded ads.

Real calls on Android, no-ops everywhere else, so ad code compiles on every target without a single #ifdef. And when [android.admob] enabled = false in raylib_multiplatform.toml, the Google Mobile Ads SDK is not in the build at all and these still compile and still do nothing.

The chain behind them: thirdparty/raymob/admob.c (JNI) -> NativeLoader.java -> AdmobBridge.java. The ad unit ids come from [android.admob].

A wrapper, not a layer: src/rmp/ads/ads.cpp forwards these to the C functions in <admob.h>, and that header stays out of yours. Those stay C because they are the real JNI boundary, and because a game in plain C — the shape of examples/plain_c/src/main.c — has no namespace to call into and can call them directly: #include <admob.h>, which is on a plain C game's include path on every target and compiles to no-ops off Android, as these do. examples/ads/01_interstitial and examples/ads/02_rewarded are both kinds of ad, end to end.

Typical use:

rmp::ads::request_rewarded();               // preload, e.g. in on_ready()
...
if (rmp::ads::is_rewarded_loaded()) rmp::ads::show_rewarded();
if (rmp::ads::take_reward_earned()) grant(rmp::ads::reward_amount());

Before shipping with ads on, read the consent (UMP) warning in README.md.

Interstitial

request_interstitial

void request_interstitial()

Start preloading one. Do it early; loading takes seconds.

is_interstitial_loaded

bool is_interstitial_loaded()

Has one finished loading?

show_interstitial

void show_interstitial()

Show it. The ad is consumed: request another one to show again.

Rewarded

request_rewarded

void request_rewarded()

Start preloading a rewarded ad, from [android.admob] rewarded_id. Do it early, and again after each one is shown: loading takes seconds.

is_rewarded_loaded

bool is_rewarded_loaded()

Has one finished loading? A button that shows it should be live only then.

show_rewarded

void show_rewarded()

Show it. The ad is consumed: request another one to show again. Nothing happens when none has loaded, and the reward is not here: it arrives through take_reward_earned(), and only if the player watched enough of the ad.

take_reward_earned

bool take_reward_earned()

True once per earned reward, and clears the flag. Poll it from the game loop; the amount is then in reward_amount().

reward_amount

int reward_amount()

The amount of the last reward earned, as set on the ad unit in AdMob. 0 until one is earned, and always 0 off Android.