mirror of
https://github.com/wassname/phaser.git
synced 2026-07-10 00:30:50 +08:00
More state swapping features and optimised Game.loop.
This commit is contained in:
+26
-19
@@ -12,35 +12,42 @@
|
||||
|
||||
(function () {
|
||||
|
||||
var state = {
|
||||
var mainMenu = {
|
||||
|
||||
preload: function() {
|
||||
|
||||
console.log('state preload called');
|
||||
game.load.image('rememberMe', 'assets/pics/remember-me.jpg');
|
||||
game.load.text('copyright', 'assets/warning - copyright.txt');
|
||||
|
||||
console.log('mainMenu preload');
|
||||
game.load.image('nocooper', 'assets/pics/1984-nocooper-space.png');
|
||||
},
|
||||
|
||||
create: function() {
|
||||
|
||||
console.log('state create called');
|
||||
|
||||
// Let's try adding an image to the DOM
|
||||
document.body.appendChild(game.cache.getImage('rememberMe'));
|
||||
|
||||
// And some text
|
||||
var para = document.createElement('pre');
|
||||
para.innerHTML = game.cache.getText('copyright');
|
||||
document.body.appendChild(para);
|
||||
|
||||
console.log('mainMenu create');
|
||||
document.body.appendChild(game.cache.getImage('nocooper'));
|
||||
}
|
||||
}
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.RENDERER_AUTO, '');
|
||||
var levelSelect = {
|
||||
|
||||
// In this instance we'll change to the state ourselves rather than pass it in the game constructor
|
||||
preload: function() {
|
||||
console.log('levelSelect preload');
|
||||
game.load.image('touhou', 'assets/pics/aya_touhou_teng_soldier.png');
|
||||
},
|
||||
|
||||
create: function() {
|
||||
console.log('levelSelect create');
|
||||
document.body.appendChild(game.cache.getImage('touhou'));
|
||||
}
|
||||
}
|
||||
|
||||
// No parameters given, which means no default state is created or started
|
||||
var game = new Phaser.Game();
|
||||
|
||||
// In this example we've created 2 states above (mainMenu and levelSelect)
|
||||
// We'll add them both to the game
|
||||
game.state.add('menu', mainMenu);
|
||||
game.state.add('select', levelSelect);
|
||||
|
||||
// Now we can either start the state we want directly, or we could have passed 'true' as the 3rd parameter in state.add
|
||||
game.state.start('select');
|
||||
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user