The Contents of Native Ad - fan-ADN/nendSDK-cocos2d-x GitHub Wiki

NendNativeAdClient

The class for load and display native ad

Constructor

public NendNativeAdClient(std::string apiKey, std::string spotID);
Parameter
  • apiKey
    apiKey published on the dashboard
  • spotID
    spotID published on the dashboard

Create

static nend_module::NendNativeAdClient* create(std::string apiKey, std::string spotID);
Parameter
  • apiKey
    apiKey published on the dashboard
  • spotID
    spotID published on the dashboard

Loading Ad

void loadAd(const std::function<void (nend_module::NendNativeAd*, NendNativeLoadResultCode, std::string)> &callback);

Loading native ad

Parameter
  • callback
    callback of the loading result
    • NendNativeAd
      Ad information object
    • NendNativeLoadResultCode
      result code
    • std::string
      error message(empty when it has done correctly)

NendNativeLoadResultCode

Definition Figure Content
NEND_SUCCESS_LOAD_AD 200 Success
NEND_FAILED_TO_REQUEST 340 Request Fail
NEND_INVALID_RESPONSE_TYPE 341 SDK error(usually it won’t happen)
NEND_INVALID_IMAGE_FORMAT 343 Ad image format is invalid.

Starts Auto reload

void enableAutoReload(const int interval, const std::function<void (nend_module::NendNativeAd*, NendNativeLoadResultCode, std::string)> &callback);
Parameter
  • interval
    Set the interval of auto-reload by second.
    (not less than 30 seconds)
  • callback
    callback of the loading result
    • NendNativeAd
      Ad information object
    • NendNativeLoadResultCode
      result code
    • std::string
      error message(empty when it has done correctly)

Disable Auto Ad Reload

void disableAutoReload();

NendNativeAd

Class to acquire ad elements, ad drawing, register click event and count impressions.

Acquire Ad Title

std::string getShortText();

Acquire Ad Text

std::string getLongText();

Acquire the Name of the Promotion

std::string getPromotionNameText();

Acquire Displaying URL

std::string getPromotionUrlText();

Acquire Action Button Text

std::string getActionButtonText();

Acquire Downloading URL for Ad Image

std::string getAdImageUrl();
  • If there is no ad image it will be empty

Acquire Downloading URL for Logo image

std::string getLogoImageUrl();
  • If there is no logo image it will be empty

Downloading Ad Image

void downloadAdImage(const std::function<void (Texture2D*, std::string)> &callback);
Parameter
  • callback
    callback of the loading result
    • Texture2D
      Ad image object
      If there is no ad image nullptr will be set up
    • std::string
      error message(empty when it has done correctly)

Downloading Logo Image

void downloadLogoImage(const std::function<void (Texture2D*, std::string)> &callback);
Parameter
  • callback
    callback of the loading result
    • Texture2D
      Ad image object
      If there is no ad image nullptr will be set up
    • std::string
      error message(empty when it has done correctly)

Register Click Event and Start Counting Impressions

Enable to click Node which is displaying ad and Label which is set advertising explicitly

void activateAdView(Node* node, Label* prLabel);
Parameter
  • node
    Node which is laid out the ad elements.
  • prLabel
    Label which is set advertising explicitly

Acquire String of Advertising Explicitly

std::string prTextForAdvertisingExplicitly(NendNativeAdvertisingExplicitly explicitly);
Parameter
  • explicitly
    Definition of Advertising Explicitly
NendNativeAdvertisingExplicitly
Definition Displayed Wording
NAD_NATIVE_ADVERTISING_EXPLIICITY_PR PR
NAD_NATIVE_ADVERTISING_EXPLIICITY_SPONSORED Sponsored
NAD_NATIVE_ADVERTISING_EXPLIICITY_AD 広告
NAD_NATIVE_ADVERTISING_EXPLIICITY_PROMOTION プロモーション

Ad Drawing

public void renderAdViews(Node* node, NendNativeAdBinder* binder, NendNativeAdvertisingExplicitly explicitly);

Drawing native ad which you have loaded

Parameter
  • node
    Node which is laid out the ad elements.
  • binder
    The class which connects to each ad element and Node to display
  • explicitly
    The definition of the display wording which will set at “advertising explicitly”.

Ad Click Callback

public void setAdClickCallback(const std::function<void (NendNativeAd*, Node*)> &callback);

Register ad click callback

Parameter
  • callback
     ad click callback
    • NendNativeAd
      NendNativeAd which have been clicked
    • Node*
      Node which is laid out the ad elements.

NendNativeAdBinder

Class to connect each ad elements of native ad and cocos2d::Label and cocos2d::Sprite.

Set Ad Element

public void setPrText_Name(std::string name);

Set the name for cocos2d::Label which displays advertising explicitly.

public void setShortTitle_Name(std::string name);

Set the name for cocos2d::Label which displays the ad title.

public void setLongText_Name(std::string name);

Set the name for cocos2d::Label which displays the ad text.

public void setPromotionName_Name(std::string name);

Set the name for cocos2d::Label which displays the promotion name.

public void setPromotionUrl_Name(std::string name);

Set the name for cocos2d::Label which displays the URL of the promotion.

public void setActionText_Name(std::string name);

Set the name for cocos2d::Label which displays the action button.

public void setAdImage_Name(std::string name);

Set the name for cocos2d::Sprite which displays the ad image.

public void setLogoImage_Name(std::string name);

Set the name for cocos2d::Sprite which displays the logo image.

auto binder = new NendNativeAdBinder();
binder->setPrText_Name("your PrText name");
binder->setShortTitle_Name("your ShortTitle name");
binder->setLongText_Name("your LongText name");
binder->setPromotionName_Name("your PromotionName name");
binder->setPromotionUrl_Name("your PromotionURL name");
binder->setActionText_Name("your ActionText name");
binder->setAdImage_Name("your AdImage name");
binder->setLogoImage_Name("your LogoImage name");

NendNativeClippingNode

Class that is succeeded cocos2d::ClippingNode
Use it when you would like to cutout the image for native ad.

create

public static NendNativeClippingNode* create(const Size clipSize, const float radius, Sprite* sprite, NendNativeClipType clipType);
Parameter
  • clipSize
    cutout size
  • radius
    angle
  • sprite
    displaying ad cocos2d::Sprite
  • clipType
    cutout type
NendNativeClipType
Definition Explanation
NEND_CLIP_CENTER Cutout starting point at the center
NEND_CLIP_TOP_LEFT Cutout starting point at the top left.
NEND_CLIP_TOP_RIGHT Cutout starting point at the top right.
NEND_CLIP_BOTTOM_LEFT Cutout starting point at the up bottom left.
NEND_CLIP_BOTTOM_RIGHT Cutout starting point at the up bottom right.
// Display Node
auto adLayer = ...;

// Display Sprite
auto adImageSprite = Sprite::create();
adImageSprite->setName("AdImage");
...

// generate the clip(The Implement example which is cutting out the center of image with size 72x72 from size 80x80)
auto clipNode = NendNativeClippingNode::create(Size(72, 72), 4.f, adImageSprite, NEND_CLIP_CENTER);
clipNode->setPosition(Point(..., ...));
// Add Sprite to the node
clipNode->addChild(adImageSprite);
...

// Add to ad Node
adLayer->addChild(clipNode);
...

// connect with binder
auto binder = new NendNativeAdBinder();
binder->setAdImage_Name("AdImage");
...