【问题标题】:Admob Phonegap build StuckAdmob Phonegap 构建卡住
【发布时间】:2017-04-08 12:40:46
【问题描述】:

好的,我在市场上有一个用于测试目的的应用程序,我正在尝试实施 admob 广告我有我的横幅广告帐户,唯一的问题是我不知道如何设置它我需要帮助请这是示例应用程序。谢谢

我需要的主要是我需要在我的标题屏幕游戏屏幕和游戏屏幕上显示横幅广告我尝试了几个教程似乎都没有让我到任何地方所以这就是为什么我决定也许你们中的一个可以帮助我解决这个问题。

This is the html file----------------------------------------------------
        <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="UTF-8-8">
        <meta name="viewport" content="user-scalable=0, initial-scale=1,minimum-scale=1, maximum-scale=1, width=device-width, minimal-ui=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
        <script type="text/javascript" src="js/phaser.js"></script>
        <script src="js/stateTitle.js"></script>
        <script src="js/characters.js"></script>


        <style>
        body {
        padding: 0px;
        margin: 0px;
        background: black;
        c       

        }

        </style>
    </head>

    <body>

        <script src="js/stateOver.js"></script>
        <script src="js/main.js"></script>


    </body>



    </body>
    </html>

----------------------------------------------------------------------------_

Main.js

    var score =0;
    var highscore =0;
    var highScoreText;
    var scoreText;

    var MainState = {



        //load the game assets before the game starts
        preload: function () {                                                    /////////////////////////////preload
            this.load.image('background', 'assets/city.png');
            this.load.image('bird', 'assets/bird.png');
            game.load.image('pipe', 'assets/pipe.png');


        },








        //executed after everything is loaded
        create: function () {                                                 

            this.background = this.game.add.sprite(0, 0, 'background');




             highScoreText = this.game.add.text(600, 40, 'HS: ' + highscore, {
                font: '25px Arial',
                fill: 'black'
            });



            /////Bird///////////////////////////////////////////////////
            this.bird = this.game.add.sprite(100, 200, 'bird');
            game.physics.startSystem(Phaser.Physics.ARCADE);
            game.physics.arcade.enable(this.bird);
            this.bird.body.gravity.y = 1000;
            var spaceKey = game.input.keyboard.addKey(
                        Phaser.Keyboard.SPACEBAR);
            game.input.onDown.add(this.jump, this); //////touch screen jump
            spaceKey.onDown.add(this.jump, this);
            this.bird.body.collideWorldBounds=true;
            this.bird.body.immovable= true;



            ///////////////////////////////////////////////////////Pipes
            this.pipes = game.add.group();

            //timer
            this.timer = game.time.events.loop(1400, this.addRowOfPipes, this);   /////////////timer for pipes

            ///////////////////////////////////////////////////////Score
            this.score = -1;
            this.labelScore = game.add.text(20, 20, "0", 
            { font: "30px Arial", fill: "black" });









        },






        // this is execated multiple times per second
        update: function () {                                           //////////////////////////////////////////////////update
            if (this.bird.y < 0 || this.bird.y > 480)   
            game.state.start("StateOver");





            ///Collision
            game.physics.arcade.overlap(
            this.bird, this.pipes, this.restartGame, null, this);


            ////////////////////////////////////////////////////////////////////////// Highscore counter
            highScoreText.text = 'HS: ' + this.currentHighScore;


                {
             if (this.score > this.currentHighScore) 
                { 
                    this.currentHighScore = this.score;
                }
    }




        }, 

        jump: function () {
            //this is for so the bird wount fly once dead
        if (this.bird.alive == false)
        return;

        ///sound
        ///this.jumpSound.play();

        // Add a vertical velocity to the bird
        this.bird.body.velocity.y = -350;

        // Jump Animation
        var animation = game.add.tween(this.bird);
        // Change the angle of the bird to -20° in 100 milliseconds
        animation.to({angle: -20}, 100);

        // And start the animation
        animation.start(); 

        game.add.tween(this.bird).to({angle: -20}, 100).start();
        },



        restartGame: function () {
        // Start the 'main' state, which restarts the game
        game.state.start(game.state.current);
        ///Hit pipe Null
        game.physics.arcade.overlap(
        this.bird, this.pipes, this.hitPipe, null, this);



    },



    addRowOfPipes: function() {

        var hole = Math.floor(Math.random() * 5) + 1; ///Math.floor(Math.random() * 5) + 1; 

        for (var i = 0; i < 10 ; i++)                ///// (var i = 0; i < 8; i++)
           if (i != hole && i != hole + 1)          ///// if (i != hole && i != hole + 1)
                this.addOnePipe(440, i * 50 );   ///// 640 starting point of pipe 240 point of down ////this.addOnePipe(480, i * 60 + 10);

        ///Score for pipes    
        this.score += 1;
        this.labelScore.text = this.score;  


    },



    addOnePipe: function(x, y) {
        var pipe = game.add.sprite(x, y, 'pipe');

        this.pipes.add(pipe);

        game.physics.arcade.enable(pipe);

        pipe.body.velocity.x = -200;

        pipe.checkWorldBounds = true;

        pipe.outOfBoundsKill = true;

    },


    hitPipe: function() {
        // If the bird has already hit a pipe, do nothing
        // It means the bird is already falling off the screen


        if (this.bird.alive == false)
            return;
        else {
            game.state.start("StateOver");
        }
        // Set the alive property of the bird to false
        this.bird.alive = false;

        // Prevent new pipes from appearing
        game.time.events.remove(this.timer);

        // Go through all the pipes, and stop their movement
        this.pipes.forEach(function(p){
            p.body.velocity.x = 0;
        }, this);






    }, 







    };

    // Initilate the Phaser Framework
    var game = new Phaser.Game(480, 640, Phaser.AUTO);
    game.state.add("main", MainState);
    game.state.add("stateTitle", stateTitle);
    game.state.add("StateOver", StateOver);
    game.state.add("characters", characters);
    game.state.start("stateTitle"); 

-----------------------------------------------------------------------------

游戏结束屏幕 stateover.js

    var StateOver={    

       preload:function()
        {
            game.load.spritesheet('button', 'assets/button.png', 215, 53, 8); 

            game.load.image("title", "assets/title.png");
            game.load.image("game", "assets/extra/gameover.png");

        },

        create:function()
        {   



            this.title = game.add.tileSprite(0, game.height-640,game.width, 640, 'title');
            this.title.autoScroll(-100,0);
            this.btnPlayAgain=game.add.button(110,400,'button',this.playAgain,this,2,3,2);
            this.btnMainMenu=game.add.button(110,300,'button',this.mainMenu,this,4,5,4);
            this.btnStore=game.add.button(110,200,'button',this.Store,this,6,7,6);
            this.game.add.sprite (118, 100, "game");

            highScoreText = this.game.add.text(130, 150, 'HS: ' + highscore, {
                font: '25px Arial',
                fill: 'black'
            });

        },
        playAgain:function()
        {
            game.state.start("main");
        },

        mainMenu:function()
        {
            game.state.start("stateTitle");
        },

        Store:function()
        {
            game.state.start("characters");
        },
        update:function()
        {        

            highScoreText.text = 'HIGHSCORE: ' + localStorage.getItem("highscore");


                {
             if (this.score > localStorage.getItem("highscore")) 
                { 
                    localStorage.setItem("highscore", this.score);
                }
            }



        },   

    };

这是主标题画面

var stateTitle={    

   preload:function()
    {
       game.load.image("logo", "assets/extra/Logo.png");
       game.load.image("title", "assets/title.png");
       game.load.spritesheet('button', 'assets/button.png', 215, 53, 8);
    },

    create:function()
    {
        this.title = game.add.tileSprite(0, game.height-640,game.width, 640, 'title');
        this.title.autoScroll(-100,0);

        this.btnStart=game.add.button(110,400,'button',this.startGame,this,0,1,1);
        this.btnStore=game.add.button(110,480,'button',this.Store,this,6,7,6);
        this.logo = game.add.sprite(60, 150, 'logo');

    },
    startGame:function()
    {
        game.state.start("main");

    },

    Store:function()
    {
        game.state.start("characters");
    },
    update:function()
    {       

    },    

};

带有示例的 HTML

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8-8">
    <meta name="viewport" content="user-scalable=0, initial-scale=1,minimum-scale=1, maximum-scale=1, width=device-width, minimal-ui=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <script type="text/javascript" src="js/phaser.js"></script>
    <script src="js/stateTitle.js"></script>
    <script src="js/characters.js"></script>


    <style>
    body {
    padding: 0px;
    margin: 0px;
    background: black;
    c       

    }

    </style>
</head>

<body>

    <script src="js/stateOver.js"></script>
    <script src="js/main.js"></script>


    <script type="text/javascript"> 
    function onDeviceready() {
    admob.createBannerView({publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB"});
    }
document.addEventListener('deviceready', onDeviceready, false);


    </script>



</body>




</html>

【问题讨论】:

  • "我已经尝试了几个教程" 向我们展示这些尝试的代码并解释您遇到的具体问题。您必须比“我不知道如何设置”更具体。
  • 这只是教程的链接。向我们展示您根据这些教程编写的代码,并具体说明您遇到了哪些错误以及您对它们的哪些困惑
  • 事情是我撤消了,因为根本没有出现让我重做它给我一秒钟。我显示的代码是我现在所拥有的,这就是为什么
  • 好的,所以在教程中的html中只是将它放在脚本标签上

标签: javascript html admob phonegap-build phaser-framework


【解决方案1】:

首先添加 admob 插件,然后在您的 html 文件中添加以下行:

<script>
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        if (AdMob)
            AdMob.prepareInterstitial({
                adId : 'ca-app-pub-xxx/yyy',
                autoShow : false
            });

        if (AdMob)
            AdMob.createBanner({
                adId : 'ca-app-pub-xxx/yyy',
                position : AdMob.AD_POSITION.BOTTOM_CENTER,
                autoShow : true,
                overlap : true
            });
    }
</script>

您可以更改横幅的位置;使用 TOP_CENTER(我不确定)而不是 BOTTOM_CENTER。

【讨论】:

  • 那么对于插件来说,它只是 confit.xml 文件的那个,对吗?那么那个phoneGap能有吗?我也可以在投放广告之前进行检查,还是必须将其投放以检查它是否有效?抱歉,直到今天晚些时候我才在电脑前
  • 我没用过phonegap但是你可以用cordova安装admob插件。你可以使用这个:github.com/floatinghotpot/cordova-admob-pro
  • 嗯,是的,这就是问题所在,因为我已经看到了一个,并且我像样本一样做了它,当我模拟它来检查添加时它不起作用,为什么没有出现在添加应该出现的地方
【解决方案2】:

好吧,我一个人尝试了很多次,我只需插入额外需要的插件就可以解决这个问题。互联网连接等 BOOOOOOOOOOOOOOM 已解决任何问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    • 2014-03-05
    • 2015-08-22
    相关资源
    最近更新 更多