我有一个很大的问题要问,因为我真的被困在这个问题上,它会被创建来在我的免费应用程序上获取广告,好的,首先我一直在关注这本书
开始 Android 游戏 2011
http://www.apress.com/9781430230427
现在这本书实现了一个非常漂亮和简单的游戏框架,我使用它(一个更简单的版本可以在这里找到
http://www.kilobolt.com/day-5-the-android-game-framework-part-i.html
现在这个框架不再使用任何类型的 XML 文件,它使用帧缓冲区将内容绘制到屏幕上。现在当应用程序第一次启动时,这是在 AndroidGame.java 中调用的第一个方法
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
int frameBufferWidth = isPortrait ? 480: 800;
int frameBufferHeight = isPortrait ? 800: 480;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
frameBufferHeight, Config.RGB_565);
float scaleX = (float) frameBufferWidth
/ getWindowManager().getDefaultDisplay().getWidth();
float scaleY = (float) frameBufferHeight
/ getWindowManager().getDefaultDisplay().getHeight();
renderView = new AndroidFastRenderView(this, frameBuffer);
graphics = new AndroidGraphics(getAssets(), frameBuffer);
fileIO = new AndroidFileIO(this);
audio = new AndroidAudio(this);
input = new AndroidInput(this, renderView, scaleX, scaleY);
screen = getInitScreen();
setContentView(renderView);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyGame");
}
我可以在哪里尝试实施 admob 横幅?这也是屏幕类的样子
public LogoScreen(Game game)
{
super(game);
}
@Override
public void update(float deltaTime)
{
Graphics g = game.getGraphics();
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for(int i = 0; i < len; i ++)
{
try
{
TouchEvent event = (TouchEvent) touchEvents.get(i);
if(event.type == TouchEvent.TOUCH_DOWN)
{
game.setScreen(new MainMenuScreen(game));
}
}
catch(IndexOutOfBoundsException io)
{
}
}
}
@Override
public void paint(float deltaTime)
{
Graphics g = game.getGraphics();
g.drawImage(Assets.logoScreen, 0, 0);
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void backButton()
{
android.os.Process.killProcess(android.os.Process.myPid());
}
如果我想在 logoScreen 中显示 admob 广告,我该怎么做?我真的很困惑如何在我的应用程序中实现 admob,如果有人能对此有所了解或帮助我,那就太好了:)
谢谢
帆布
---更新--- 这是 FastRenderView 的代码
package com.CC.framework.implementation;
//Imports
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class AndroidFastRenderView extends SurfaceView implements Runnable
{
//Variables
AndroidGame game;
Bitmap framebuffer;
Thread renderThread = null;
SurfaceHolder holder;
volatile boolean running = false;
public AndroidFastRenderView(AndroidGame game, Bitmap framebuffer)
{
super(game);
this.game = game;
this.framebuffer = framebuffer;
this.holder = getHolder();
}
public void resume()
{
running = true;
renderThread = new Thread(this);
renderThread.start();
}
public void run()
{
Rect dstRect = new Rect();
long startTime = System.nanoTime();
while(running)
{
if(!holder.getSurface().isValid())
{
continue;
}
float deltaTime = (System.nanoTime() - startTime) / 10000000.000f;
startTime = System.nanoTime();
if (deltaTime > 3.15)
{
deltaTime = (float) 3.15;
}
game.getCurrentScreen().update(deltaTime);
game.getCurrentScreen().paint(deltaTime);
Canvas canvas = holder.lockCanvas();
canvas.getClipBounds(dstRect);
canvas.drawBitmap(framebuffer, null, dstRect, null);
holder.unlockCanvasAndPost(canvas);
}
}
public void pause()
{
running = false;
while(true)
{
try
{
renderThread.join();
break;
}
catch (InterruptedException e)
{
// retry
}
}
}
}