cocos2dx游戏接入广告常见问题

1. 简介

本文主要介绍cocos2dx3.17 安卓项目在接入广告SDK的过程中如何处理常见的问题。(例如穿山甲广告,华为广告,topon聚合类广告)

2. 常见问题

2.1 展示广告过程中按home键退到后台,再点击应用logo回来,广告不见了或者没有回调?
  • 检查应用的启动Activity的Manifest配置,launchMode需要是standard。
<activity android:name=".Scmj"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:screenOrientation="sensorLandscape"
    android:launchMode="standard"
    android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
  • 在启动Activity的onCreate()方法中添加如下代码:
@Override
public void onCreate(Bundle savedInstanceState) {
    ...
    
    super.onCreate(savedInstanceState);

    //展示广告过程中按home键退到后台,再点击应用logo回来依然展示广告
    if (!isTaskRoot()) {
        Intent intent = getIntent();
        String action = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null && action.equals(Intent.ACTION_MAIN)) {
            Log.i(TAG, "onCreate with flag FLAG_ACTIVITY_BROUGHT_TO_FRONT");
            finish();
            return;
        }
    }
    
    ...
}

2.2 banner广告尺寸、位置问题。

1.Banner广告以View的形式提供广告的API,View可以自定义宽高,但是部分广告平台不一定能适配自定义的宽高,所以在游戏中设置banner广告的宽高时要与在广告后台配置的宽高比一致,且需要经过测试看看实际效果来进行调整;
2.调用广告SDK提供的API去展示banner使用的是“屏幕坐标系”(原点为屏幕左下角,x 向右,y 向上),而cocos2dx游戏使用的是“笛卡尔坐标系”(原点为屏幕左上角,x 向右,y 向下)。所以需要进行转换,转换时需要考虑到游戏的适配方案:

还有 43% 的精彩内容
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
支付 ¥5.50 继续阅读

相关阅读更多精彩内容

友情链接更多精彩内容