0

Ok I have an application on the market for testing purposes and Im trying to implement admob ads I have my account for banner ads and everything the only thing is that I dont know how to set it up I need help please this is the sample application. Thank you

Mostly what i need i need to show banner ads on my title screen game screen and game over screen Ive tried several tutorials none seem to get me anywhere so thats why i decided maybe here one of you can help Me with this.

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"); 

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

Game over screen 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);
                }
            }



        },   

    };

This is the main title screen

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 with sample

<!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>
Bruno 58
  • 95
  • 13
  • "_I've tried several tutorials_" Show us the code for those attempts and explain what specific issue you encountered. You are going to have to be much more specific than "_I don't know how to set it up_". – takendarkk Mar 13 '17 at 19:18
  • 1
    https://github.com/appfeel/admob-phonegap-build-demo – Bruno 58 Mar 13 '17 at 19:19
  • That is just a link to the tutorial. Show us YOUR code that YOU wrote according to those tutorials and _explain specifically what errors you got and what confused you about them_. – takendarkk Mar 13 '17 at 19:20
  • Thing is I undid that since simply nothing was showing up let me redo it give me a sec. the code Im showing is what i have as of right now thats why – Bruno 58 Mar 13 '17 at 19:24
  • Ok so in the html as in the tutorial is just to place this on the script tag – Bruno 58 Mar 13 '17 at 19:31
  • https://www.npmjs.com/package/phonegap-admob – Bruno 58 Mar 13 '17 at 19:31
  • – Bruno 58 Mar 13 '17 at 19:32
  • You can edit your question instead of trying to put code in comments. – takendarkk Mar 13 '17 at 19:37

2 Answers2

0

Firstly add admob plugin then just add below lines to your html file:

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

You can change the place of the banner; use TOP_CENTER (I am not sure about this) instead of BOTTOM_CENTER.

mg52
  • 116
  • 1
  • 7
  • So for the plugin it's just the one for the confit.xml file correct? So that phoneGap can have it? Also can I check this before I put the ad live or I have to put it to live to check if it works? Sry I'm not in the computer yet until later today – Bruno 58 Mar 17 '17 at 13:37
  • I have not used phonegap but you can use cordova to install admob plugin. You can use this: https://github.com/floatinghotpot/cordova-admob-pro – mg52 Mar 17 '17 at 19:04
  • Hmm yea thats the problem its cz Ive seen that one and Ive do it like the samples and when i emulate it to check for adds it doesnt work idk why nothing shows up where the the add should show up – Bruno 58 Mar 20 '17 at 04:02
0

Ok SOOOOO many tries alone I was able to fix this by simply inserting the extra needed plugins. Internet connection etc. BOOOOOOOOOOOOOOM Fixed any questions ask.

Bruno 58
  • 95
  • 13