想要在游戏结束后在我的游戏中展示AdMob插页式广告

时间:2015-04-26 18:29:17

标签: android admob ads google-play-games interstitial

我想在每场比赛结束后展示广告(非页内广告),但我面临一些问题。有人可以帮我实现AdMob interstitial吗?

此GameResultLayer(活动)

import javax.microedition.khronos.opengles.GL10;

import org.cocos2d.layers.CCScene;
import org.cocos2d.menus.CCMenu;
import org.cocos2d.menus.CCMenuItem;
import org.cocos2d.menus.CCMenuItemImage;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabel;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.transitions.CCFadeTransition;
import org.cocos2d.types.CGPoint;
import org.cocos2d.types.ccColor3B;
import android.app.Activity;


public class GameResultLayer extends BaseLayer{

    long    m_tick;
    boolean again = false;
    public static CCScene scene(BaseActivity activity){
        CCScene scene = CCScene.node();
        GameResultLayer layer = new GameResultLayer(activity);
        scene.addChild(layer);
        return scene;
    }

    public GameResultLayer(Activity activity) {
        super(activity);

        this.initialize();
    }

    public void initialize() {
        if(GameLayer.sharedInstance().m_fDistance > G.g_nBestDistance)
            G.g_nBestDistance =(int) GameLayer.sharedInstance().m_fDistance;
        activity.saveSettings();

        CCSprite sprBG = CCSprite.sprite("game_result_bg.png");
        this.addChild(sprBG);
        sprBG.setPosition(CGPoint.ccp(G.DEFAULT_WIDTH / 2, G.DEFAULT_HEIGHT / 2));

        CCLabel m_lblDistance = CCLabel.makeLabel(String.format("%d", (int)GameLayer.sharedInstance().m_fDistance), "SanitariumBB.ttf", 18 * G.SCALE_X);
        m_lblDistance.setPosition(CGPoint.ccp(114 * G.SCALE_X, 246 * G.SCALE_Y));
        m_lblDistance.setRotation(-30.0f);
        this.addChild(m_lblDistance);

        CCLabel m_lblBestDistance = CCLabel.makeLabel(String.format("%d", G.g_nBestDistance), "SanitariumBB.ttf", 18 * G.SCALE_X);
        m_lblBestDistance.setPosition(CGPoint.ccp(317 * G.SCALE_X, 246 * G.SCALE_Y));
        m_lblBestDistance.setRotation(30.0f);
        this.addChild(m_lblBestDistance);

        /*
         * Button Home
         */
        CCMenuItem btnHomeItem  = CCMenuItemImage.item("btn_home.png", "btn_home.png", this,"onHome");
        CCMenu btnHome = CCMenu.menu(btnHomeItem);
        btnHome.setPosition(CGPoint.ccp(181 * G.SCALE_X, 66 * G.SCALE_Y));
        this.addChild(btnHome);

        /*
         * Button Facebook
         */
        CCMenuItem btnFacebookItem  = CCMenuItemImage.item("btn_facebook.png", "btn_facebook.png", this,"onFacebook");
        CCMenu btnFacebook = CCMenu.menu(btnFacebookItem);
        btnFacebook.setPosition(CGPoint.ccp(126 * G.SCALE_X, 66 * G.SCALE_Y));
        this.addChild(btnFacebook);

        /*
         * Button PlayAgain
         */
        CCMenuItem btnPlayAgainItem  = CCMenuItemImage.item("btn_playagain.png", "btn_playagain.png", this,"onPlayAgain");
        CCMenu btnPlayAgain = CCMenu.menu(btnPlayAgainItem);
        btnPlayAgain.setPosition(CGPoint.ccp(268 * G.SCALE_X, 66 * G.SCALE_Y));
        this.addChild(btnPlayAgain);

        CCLabel lblGem = CCLabel.makeLabel(String.format("%d", G.g_nGems), "SanitariumBB.ttf", 16 * G.SCALE_X);
        lblGem.setPosition(CGPoint.ccp(263 * G.SCALE_X, 187 * G.SCALE_Y));
        lblGem.setColor(ccColor3B.ccc3(131, 73, 5));
        this.addChild(lblGem);

        CCLabel lblCoin = CCLabel.makeLabel(String.format("%d", G.g_nCoins), "SanitariumBB.ttf", 16 * G.SCALE_X);
        lblCoin.setPosition(CGPoint.ccp(263 * G.SCALE_X, 136 * G.SCALE_Y));
        lblCoin.setColor(ccColor3B.ccc3(131, 73, 5));
        this.addChild(lblCoin);
    }

    /*
     * Home Action
     */
    public void onHome(Object sender) {
        activity.playSystemEffect(G.EFFECT_ID.E_CLICK);
        G.g_bGamePaused = false;
        this.removeAllChildren(true);
        GameLayer.sharedInstance().unscheduleAllSelectors();
        CCDirector.sharedDirector().replaceScene(new CCFadeTransition(0.5f, MainViewLayer.scene(activity)));
    }

    /*
     * Play Again Action
     */
    public void onPlayAgain(Object send) {
        activity.playSystemEffect(G.EFFECT_ID.E_CLICK);
        G.g_bGameStarted = false;
        G.g_bGameOver = false;
        G.g_bGamePaused = false;

        this.removeAllChildren(true);
        GameLayer.sharedInstance().unscheduleAllSelectors();

        m_tick = 0;
        again = true;
        CCSprite sprBack = CCSprite.sprite("loading.png");
        sprBack.setPosition(CGPoint.ccp(G.DEFAULT_WIDTH/2, G.DEFAULT_HEIGHT/2));
        this.addChild(sprBack);

    }

    /*
     * Facebook Action
     */
    public void onFacebook(Object send) {
        activity.playSystemEffect(G.EFFECT_ID.E_CLICK);
        activity.onFacebook((int) GameLayer.sharedInstance().m_fDistance);

    }

    @Override
    public void draw(GL10 gl) {
        m_tick++;
        if(m_tick > 1) {
            if(m_tick == 60 && again == true){
                again = false;
                CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(0.5f, GameLayer.scene(activity)));
            }
        }
        super.draw(gl);
    }
}

非常感谢你

1 个答案:

答案 0 :(得分:0)

您想要做的是:

  1. 游戏开始时加载插页式广告
  2. 在游戏结束时, IF 加载插页式广告,然后展示。
  3. 请参阅https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial