ADMOB整合到AND GENTINE基底验证中,替代表面视图



好的。因此,我一直在Android中使用AndEngine制作游戏应用程序。我已经达到了要在游戏中实现广告的地步,并且我一直在尝试将ADMOB用于此目的。

问题是,每个示例和我在Internet上找到的所有示例都可以使用布局。我正在创建的游戏不会利用任何布局。它使用相机功能显示事物。即

@Override
public EngineOptions onCreateEngineOptions() {
    camera = new Camera(0, 0, 1024f, 1024f);
    EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.camera);
    engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
    return engineOptions;
}

是否有可能使用相机显示横幅广告?

谢谢。

实际上没有。但是仍在使用和引擎,您可以使用布局显示广告。这是我在AND GEANTING游戏中使用的示例(它基于AndEngine Forum的修改示例:http://www.andengine.org/forums/tutorials/google-admob-inmob-inmob-inmob-ingine-tutorial-t10822.html):

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DisplayMetrics displayMetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

this.adView = new AdView(this);
this.adView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
this.adView.setAdUnitId("PUT YOUR NUMBER");
com.google.android.gms.ads.AdRequest adrequest = new com.google.android.gms.ads.AdRequest.Builder().build(); //you can use test device as you did in your code

this.adView.loadAd(adrequest);
RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

layout.addView(this.mRenderSurfaceView);

layout.addView(this.adView, params);
}

此示例用于智能横幅广告。论坛示例中显示了显示和隐藏它们的方法。

最新更新