2017-03-13 13 views
0

私はテスト目的で市場にアプリケーションを持っています。私はadmob広告を実装しようとしています。私はバナー広告のアカウントを持っています。唯一のことはセットアップ方法を知らないことです。これはサンプルアプリケーションです。ありがとうございましたAdmob Phonegap build Stuck

私は私のタイトル画面のゲーム画面と画面上のゲームにバナー広告を表示する必要があります。私はどこでも私を得ることはできませんでした。この。

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() 
    {  

    },  

}; 
01です

サンプル

<!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> 
+0

「私はいくつかのチュートリアルを試しました_」これらの試みのコードを表示し、遭遇した特定の問題を説明します。あなたは "私はそれをどう設定するか分からない"よりはるかに具体的にする必要があります。 – csmckelvey

+1

https://github.com/appfeel/admob-phonegap-build-demo –

+0

これは単なるチュートリアルへのリンクです。これらのチュートリアルにしたがってあなたが書いたあなたのコードを表示してください。そして、あなたが得たエラーとあなたについて何が混乱しているかを具体的に説明してください。 – csmckelvey

答えて

0

Ok SOOOOO多くの試みだけで、私は余分な必要なプラグインを挿入するだけでこれを解決できました。インターネット接続など。BOOOOOOOOOOOOOOM質問が修正されました。

0

まずAdMobのプラグインを追加してHTMLその後、ちょうどあなたの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> 

あなたがバナーの場所を変更することができます。 BOTTOM_CENTERではなくTOP_CENTERを使用してください(これについてはわかりません)。

+0

プラグインの場合、confit.xmlファイルのプラグインだけが正しいですか?だからphoneGapはそれを持つことができますか?広告を掲載する前にこれを確認することもできますし、それが動作するかどうかを確認するためにはライブに入れる必要がありますか? Sry私はまだコンピュータにいません。今日までは –

+0

私はphonegapを使用していませんが、cordovaを使用してadmobプラグインをインストールできます。あなたはこれを使うことができます:https:// github。com/floatinghotpot/cordova-admob-pro – mg52

+0

Hmm yea that that cz Iveは、サンプルが好きで、それを確認するためにエミュレートすると、何も表示されません。現れる –

関連する問題