Hello,
I cannot manage to make Phaser continue updating stage while I am doing something in background. In particular, I noticed that to generate stage I need 2-4 seconds (resources are loaded but generation itself takes this time). So I decided to add loading by default withing create() method and call actual stage creation asynchronously by calling it in setTimeout(function() {}, 0). However, Phaser freezes tween animation:
var sprite = this.add.sprite(100, 100, 'loading');
this.game.add.tween(sprite.scale).to({x: 1.5, y: 1.5}, 500, Phaser.Easing.Linear.None, true, 0, -1, true);
setTimeout(function(that) {
var time_now = (new Date()).getTime();
while ((new Date()).getTime() - time_now < 2000) {}
sprite.visible = false;
}, 0, this);
I attached two short files, one is with while loop (to simulate some work) and dot is not animating, the second one is without while loop and visible = false statement
var sprite = this.add.sprite(100, 100, 'loading');
this.game.add.tween(sprite.scale).to({x: 1.5, y: 1.5}, 500, Phaser.Easing.Linear.None, true, 0, -1, true);
setTimeout(function(that) {
var time_now = (new Date()).getTime();
// while ((new Date()).getTime() - time_now < 2000) {}
// sprite.visible = false;
}, 0, this);
If that's not a way to do what I want to do then how can I show animation while I am preparing stage?