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

Posted

技术标签:

【中文标题】想要在游戏结束后在“我的游戏”中展示 AdMob 插页式广告【英文标题】:Want to show AdMob Interstitial ads in My Game after game over 【发布时间】:2015-07-05 01:54:16 【问题描述】:

我想在每场比赛结束后展示广告(插页式),但我遇到了一些问题。有人可以帮我实施 AdMob 插页式广告吗?

这个 GameResultLayer(activity)

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】:

你想做的是:

    游戏开始时加载插页式广告 游戏结束时,如果加载了一个插页式广告,然后显示它。

见https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial

【讨论】:

你能帮我添加这个活动吗?我想在用户再次按下按钮播放时出现广告。谢谢 我告诉过你确切地怎么做。阅读我提供的文档。

以上是关于想要在游戏结束后在“我的游戏”中展示 AdMob 插页式广告的主要内容,如果未能解决你的问题,请参考以下文章

如何在统一游戏中投放 Admob 广告?

unity 横幅广告 admob v5.3.0 不显示

集成Admob后,我的Libgdx游戏速度变慢

对 Admob 广告的高请求低印象

Admob 在“广告”标签中发送消息

Admob 插页式接收请求但不填充广告