我正在构建一个由AndEngine游戏框架提供支持的android游戏
我正在使用以下代码与Admob进行关联:
@Override
protected void onSetContentView() {
mRenderSurfaceView = new RenderSurfaceView(this, mEngine);
mRenderSurfaceView.applyRenderer();
setContentView(R.layout.main);
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT);
AdView adView = new AdView(this, AdSize.BANNER, "XXXXXXX");
adView.refreshDrawableState();
adView.setVisibility(AdView.VISIBLE);
final FrameLayout.LayoutParams adViewLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
adRequest.addTestDevice(Secure.ANDROID_ID);
adView.loadAd(adRequest);
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(adView, adViewLayoutParams);
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
在游戏中,当球被创建时,它会在动画中逐渐消失
我用一根线做的:
new Thread(new Runnable() {
public void run() {
mBody.setType(BodyType.StaticBody);
mSprite.setAlpha(0.0f);
try {
while(mSprite.getAlpha() < 1.0f) {
mSprite.setAlpha(mSprite.getAlpha() + 0.01f);
Thread.sleep(3);
}
mBody.setType(BodyType.DynamicBody);
mBody.setLinearVelocity(new Vector2(0, 10));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
问题是:
动画效果很好,但是
添加Admob代码时,Sprite会出现一秒钟
然后就消失了。
在我看来,这两块代码之间似乎存在问题
但我无法确定解决方案,甚至无法确定是什么原因导致了这个问题的发生。
我只知道当Admob代码在我的应用程序中组合时,动画不起作用。
我想知道为什么以及如何解决它。谢谢大家
这可能完全无关,但我最近遇到了一个随机消失的精灵的问题,尽管我与Admob没有联系。当我在设置引擎的地方添加以下行时,问题就消失了:
engineOptions.getRenderOptions().disableExtensionVertexBufferObjects();
我建议您使用XML文件来放置管理员。它更干净,易于使用,根据我自己的测试,它比覆盖onsetcontentview更快。为了实现这一点,你需要扩展LayoutGameActivity(该类也有一个简单的版本。如果我没有错的话,SimpleLayoutActivity)
我拿到电脑后会改进答案。