-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
832bdc3
commit fc14797
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/loader/load-complete-promise.js | ||
cd .. | ||
cd .. | ||
npm run dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import LoadCompletePromise from '../../plugins/utils/loader/LoadCompletePromise'; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { | ||
LoadCompletePromise(this, { | ||
type: 'image', | ||
key: 'classroom', | ||
url: 'assets/images/backgrounds/classroom.png' | ||
}) | ||
.then(function (result) { | ||
console.log(result) | ||
}) | ||
} | ||
|
||
create() { | ||
this.add.image(400, 300, 'classroom'); | ||
} | ||
|
||
update() { } | ||
} | ||
|
||
var config = { | ||
type: Phaser.AUTO, | ||
parent: 'phaser-example', | ||
width: 800, | ||
height: 600, | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
scene: Demo | ||
}; | ||
|
||
var game = new Phaser.Game(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var LoadCompletePromise = function (scene, config) { | ||
return new Promise(function (resolve, reject) { | ||
var type = config.type; | ||
delete config.type; | ||
var key = config.key; | ||
scene | ||
.load[type](config) | ||
.on(`filecomplete-${type}-${key}`, function (key, type, data) { | ||
resolve({ | ||
key: key, | ||
type: type, | ||
data: data, | ||
}); | ||
}) | ||
.start() | ||
}); | ||
}; | ||
|
||
export default LoadCompletePromise; |