如何使用Phaser消除Facebook即时游戏的加载进度
我正在用Phaser 2 CE为Facebook即时游戏开发一个游戏,我不喜欢在开始时显示的加载进度,我如何才能摆脱它? 我使用的是如何使用Phaser消除Facebook即时游戏的加载进度,facebook,phaser-framework,facebook-instant-games,Facebook,Phaser Framework,Facebook Instant Games,我正在用Phaser 2 CE为Facebook即时游戏开发一个游戏,我不喜欢在开始时显示的加载进度,我如何才能摆脱它? 我使用的是 FBInstant.initializeAsync() .然后(函数(){ var images=['phaser2']; 对于(var i=0;i
FBInstant.initializeAsync()
.然后(函数(){
var images=['phaser2'];
对于(var i=0;i
您可以尝试下面的代码,然后创建您的游戏,我知道它不干净,但可以工作
FBInstant.initializeAsync()
.then(function() {
FBInstant.setLoadingProgress(50);
FBInstant.setLoadingProgress(100);
});
我试过一些有趣的东西,但根据我的经验,它并不能回答问题
var-sprite;
var PixelW=window.innerWidth;
var PixelH=window.innerHeight;
var game=new Phaser.game(PixelW,PixelH,Phaser.AUTO,'game',{preload:preload,create:create,update:update});
函数预加载(){
game.load.onLoadStart.add(loadStart,this);
game.load.onFileComplete.add(fileComplete,this);
惊人的负荷();
}
函数加载(){
game.load.image('logo1','assets/sprites/phaser1.png');
game.load.image('logo2','assets/sprites/phaser2.png');
game.load.image('dude','assets/sprites/phaser dude.png');
game.load.image('ship'、'assets/sprite/phaser ship.png');
game.load.image('sumble','assets/sprites/mumble.png');
game.load.image('mushroom2','assets/sprites/mushroom2.png');
game.load.image('diamond','assets/sprites/diamond.png');
game.load.image('bunny','assets/sprites/bunny.png');
game.load.start();
}
函数create(){
game.stage.backgroundColor=0x3b5998;
game.scale.scaleMode=Phaser.ScaleManager.SHOW_ALL;
sprite=game.add.sprite(game.world.centerX,game.world.centerY,'dude');
sprite.inputEnabled=true;
添加(myHandler,this);
var text=game.add.text(10,10,PixelW+“”+“”+PixelH,{font:“65px Arial”,fill:“#ffffff00”,align:“center”});
}
函数loadStart(){
}
//通过以下参数发送此回调:
函数fileComplete(进度、缓存键、成功、总加载、总文件){
FBInstant.setLoadingProgress(进度);
//console.log(cacheKey+“”+进度);
}
函数myHandler(){
sprite.anchor.setTo(0.5,0.5);
sprite.x=Math.floor(Math.random()*PixelW);
sprite.y=Math.floor(Math.random()*像素);
}
函数更新(){
}
var p=0;
FBInstant.initializeAsync()
.然后(函数(){
//FBInstant.setLoadingProgress(50);
//FBInstant.setLoadingProgress(100);
});
//加载所有资产后,通知SDK
//结束加载视图并开始游戏
FBInstant.startGameAsync()
.然后(函数(){
//只能检索上下文和播放器信息
//一旦startGameAsync()解析
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();
//一旦startGameAsync()解析,这也意味着加载视图
//已删除,用户可以看到游戏视口
//game.start();
});
我使用以下方法,在使用Phaser加载每个文件后增加加载百分比。此外,我还包括一个尝试捕捉,以便在测试本地游戏时,游戏不会崩溃
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);
},
我是这样做的。你可以从那里开始建设
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
}
})
})
我认为没有人关心这个进程,而这个代码使游戏复杂化,比如说
FBInstant.setLoadingProgress(100)
在这种情况下是正确的您可能是对的,但我发现最好使Facebook的加载进度与中的资产加载进度相匹配Phaser@albator2018你的评论似乎与你的问题相矛盾。你确定这个问题的措辞正确吗?
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
}
})
})