Admob Phonegap build Stuck

时间:2017-03-13 19:15:18

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

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

大多数我需要的东西我需要在我的标题屏幕游戏屏幕上显示横幅广告和屏幕上的游戏我曾尝试过几个教程似乎没有让我任何地方,所以这就是为什么我决定在这里你们中的一个可以帮助我。 / p>

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>

2 个答案:

答案 0 :(得分:0)

首先添加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。

答案 1 :(得分:0)

好的SOOOOO很多尝试单独我能够通过简单地插入额外需要的插件来解决这个问题。互联网连接等.BOOOOOOOOOOOOOOOM修正了任何问题。