Class TAds

Unit

Declaration

type TAds = class(TComponent)

Description

Advertisements in game. Right now only on Android (does nothing on other platforms, as CastleMessaging does nothing on non-Android platforms).

Usage:

  1. Create an instance of this class (only a single instance allowed).

  2. Initialize at least one ad network using one of the InitializeXxx methods. Usually you want to call the initialization from TCastleApplication.OnInitialize.

  3. Use remaining methods of this class to show / hide ads, like ShowFullScreenAd, ShowBanner, HideBanner.

  4. To include the necessary integration code in your Android project, declare your Android project type as "integrated" with the appropriate services (admob, chartboost, startapp, heyzap...) inside CastleEngineManifest.xml . See https://github.com/castle-engine/castle-engine/wiki/Android-Project-Services-Integrated-with-Castle-Game-Engine .

Hierarchy

  • TComponent
  • TAds

Overview

Methods

Protected procedure FullScreenAdClosed(const WatchedStatus: TAdWatchStatus); virtual;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string);
Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId: string; const TestDeviceIds: array of string);
Public procedure InitializeStartapp(const AppId: string);
Public procedure InitializeChartboost(const AppId, AppSignature: string);
Public procedure InitializeHeyzap(const PublisherId: string);
Public procedure ShowFullScreenAd(const AdNetwork: TAdNetwork; const AdType: TFullScreenAdType; const WaitUntilLoaded: boolean);
Public procedure ShowBanner(const AdNetwork: TAdNetwork; const HorizontalGravity: THorizontalPosition; const VerticalGravity: TVerticalPosition);
Public procedure HideBanner(const AdNetwork: TAdNetwork);
Public procedure StartTestActivity(const AdNetwork: TAdNetwork);

Properties

Public property OnFullScreenAdClosed: TAdClosedEvent read FOnFullScreenAdClosed write FOnFullScreenAdClosed;
Public property BannerSize: TRectangle read FBannerSize;

Description

Methods

Protected procedure FullScreenAdClosed(const WatchedStatus: TAdWatchStatus); virtual;
 
Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string);

Initialize AdMob ads. You need to create the unit ids on AdMob website (or use TestAdMobBannerUnitId, TestAdMobInterstitialUnitId for testing).

TestDeviceIds may be empty, or it may contain a list of devices where you always want to see test ads — even with real (non-test) ad units. This is useful when you test ads in your application (with real ad units, on a real phone). Paste here the list of your devices (see https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start , you can see your device ids in "adb logcat" output) in order to avoid getting banned for clicking on your own ads.

Usually called from TCastleApplication.OnInitialize.

Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId: string; const TestDeviceIds: array of string);
 
Public procedure InitializeStartapp(const AppId: string);

Initialize StartApp ads. You need to register your game on http://startapp.com/ to get app id.

Usually called from TCastleApplication.OnInitialize.

Public procedure InitializeChartboost(const AppId, AppSignature: string);

Initialize Chartboost ads. You need to register your game on http://chartboost.com/ to get app id and signature.

Usually called from TCastleApplication.OnInitialize.

Public procedure InitializeHeyzap(const PublisherId: string);

Initialize Heyzap ads. You need to register your game on https://www.heyzap.com/ to get publisher id.

Usually called from TCastleApplication.OnInitialize.

Public procedure ShowFullScreenAd(const AdNetwork: TAdNetwork; const AdType: TFullScreenAdType; const WaitUntilLoaded: boolean);

Show full-screen ad, interstitial (in-between) or reward ad.

Not all ad networks support (or differentiate between) all full-screen ad types possible in TFullScreenAdType enumeration. So we eventually show other sensible ad type instead.

If WaitUntilLoaded, then we wait until the ad contents are fetched (be sure to show some "loading" state to user, as it may take a while in case of a slow network). If not WaitUntilLoaded, then we immediately resign if ad is not loaded yet. Not all ad implementations support this setting reliably, so this is only a suggestion.

In any case, after this method is called, we make sure to call callback OnFullScreenAdClosed sometime.

Public procedure ShowBanner(const AdNetwork: TAdNetwork; const HorizontalGravity: THorizontalPosition; const VerticalGravity: TVerticalPosition);

Show banner ad. Banners are not supported by all ad networks (only AdMob and Heyzap now), in case they are unsupported this call is silently ignored.

Public procedure HideBanner(const AdNetwork: TAdNetwork);

Hide banner ad. Banners are not supported by all ad networks (only AdMob and Heyzap now), in case they are unsupported this call is silently ignored.

Public procedure StartTestActivity(const AdNetwork: TAdNetwork);

Show Heyzap activity to test various ad networks integrations. This is for now supported only by anHeyzap.

Properties

Public property OnFullScreenAdClosed: TAdClosedEvent read FOnFullScreenAdClosed write FOnFullScreenAdClosed;
 
Public property BannerSize: TRectangle read FBannerSize;
 

Generated by PasDoc 0.15.0.