Ads in cocos2d-x app

Hello.

How I can use ads in my application?

I tried to rework the example of Samsung:
@
result GameField::CreateControl(void)
{
result r = E_SUCCESS;
*pAd = new Ad;
r =*pAd~~>Construct, L“2100000003_001”, this);
__pAd~~>SetTextColor(Osp::Graphics::Color(255, 255, 255));
*pAd~~>SetBackgroundColor);
ArrayList* pKeywordsList = new ArrayList;
pKeywordsList~~>Construct;
*pAd~~>SetKeywords;
delete pKeywordsList;
HashMap* pExtraInfoList = new HashMap;
pExtraInfoList~~>Construct();
__pAd->SetExtraInfo(pExtraInfoList);
delete pExtraInfoList;
r = Application::GetInstance()->GetAppFrame()->GetFrame()->AddControl(*__pAd);
return r;
}
@
But in runtime this generates error “[E_INVALID_ARG] Cannot add the target control to a frame.”

Thanks.

P.S. Sorry for my bad English

Hi, Where do you invoke CreateControl?

In GameField::init, GameField scene is created in AppDelegate::applicationDidFinishLaunching

OK, I will test this issue.:slight_smile:

Hi, I reviewed the code of ‘AdControl’, found that ad control is added to Form rather than Frame. So try the code as follow.

CCEGLView::sharedOpenGLView().AddControl(*_pAd);

It works!
Thanks for help!

Not at all!:slight_smile: