如何摆脱使用Phaser的Facebook Instant Games的加载进度

时间:2018-05-13 09:57:20

标签: facebook phaser-framework

我正在使用Phaser 2 CE为Facebook即时游戏开发游戏,我不喜欢起点上显示的加载进度,我该如何摆脱它? 我使用Quick Start page

中给出的默认示例
      FBInstant.initializeAsync()
      .then(function() {
        var images = ['phaser2'];
        for (var i=0; i < images.length; i++) {
         var assetName = images[i];
         var progress = ((i+1)/images.length) * 100;
         game.load.image('./assets/' + assetName + '.png'); 
         // Informs the SDK of loading progress
         FBInstant.setLoadingProgress(progress);  
        }
      });

3 个答案:

答案 0 :(得分:1)

您可以尝试this example中给出的类似下面的代码,然后创建您的游戏,我知道它不干净但是有效

<!DOCTYPE html>
 <html>
<head>
 <title></title>
</head>
<body>
<?php

require "vendor/autoload.php";

 use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

 $developmentMode = true;
 $mailer = new PHPMailer($developmentMode);

  try {
     $mailer->SMTPDebug = 2;
    $mailer->isSMTP();            //edited here


 if ($developmentMode) {

   $mailer->SMTPOptions = [
    'ssl'=> [
         'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
      ]
   ];

 } 

 $mailer->Host = 'smtp.gmail.com';
$mailer->SMTPAuth = true;
 $mailer->Username = "mygmail@gmail.com";
 $mailer->Password = "password";
 $mailer->SMTPSecure = 'tls';
$mailer->Port = 587;

$mailer-> setFrom("mygmail@gmail.com", "Izaya");
$mailer->addAddress("anothergmail@gmail.com","orihara");

  $mailer->isHTML(true);
   $mailer->Subject = "Hey There";
  $mailer->Body = "NICE TO MEET YOU IZAYA ";


   $mailer->send();
$mailer->ClearAllRecipients();
  echo "Mail has been Sent";



   }catch (Exception $e) {
echo "Email Error.INFO:" . $mailer->ErrorInfo;

  }


  ?>
 </body>
 </html>

答案 1 :(得分:0)

我使用以下方法,在使用Phaser加载每个文件后,我增加了加载百分比。另外,我还提供了一个try catch,以便在测试本地游戏时不会崩溃。

      preload: function () {
        try{
            FBInstant.initializeAsync()
                .then(function() {        
                });
            }
            catch(err) {
            console.log('FB Instant Games Error: No Internet Connected');
        }
        this.load.image('gameItem1', 'assets/sprite/game_item1.png');
        this.load.image('gameItem2', 'assets/sprite/game_item2.png');
      }

然后...

      startFacebookGame: function(){
        try{
          FBInstant.startGameAsync()
            .then(function() {
            // Retrieving context and player information can only be done
            // once startGameAsync() resolves
            var contextId = FBInstant.context.getID();
            var contextType = FBInstant.context.getType();

            var playerName = FBInstant.player.getName();
            var playerPic = FBInstant.player.getPhoto();
            var playerId = FBInstant.player.getID();

            // Once startGameAsync() resolves it also means the loading view has 
            // been removed and the user can see the game viewport
          });
        }
        catch(err) {
          console.log('Analytics Connection Error');
        }
      },

      fileComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) {
        try{
          FBInstant.setLoadingProgress(progress);
        }
          catch(err) {
          console.log('FB Instant Games progress Failed: No Internet Connected.');
        }

        //console.log("Progress: " + progress);
      },

答案 2 :(得分:0)

这就是我的方法。您可以从那里开始。

function preload() {
    // Load some assets
    FBInstant.setLoadingProgress(100)
}

function create() {
    FBInstant
        .startGameAsync()
        .then(() => {
            // Here you can now get users name etc.
            console.log(this)
        })
}

FBInstant.initializeAsync()
    .then(() => {
        new Phaser.Game({
            type: Phaser.AUTO,
            width: window.innerWidth,
            height: window.innerHeight,
            scene: {
                preload,
                create
            }
        })
    })