一番簡単な方法でPhaserの基本的なHTMLを作成します。ES6のクラス定義ではなく、まずは関数を使った方法での作成方法です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<!doctype html> <html lang="ja"> <head> <meta charset="UTF-8"> <script src="//cdn.jsdelivr.net/npm/phaser@3.17.0/dist/phaser.js"></script> <style> body { margin: 0; } </style> <script> var config = { type: Phaser.AUTO, width: 800, height: 600, scene: { preload: preload, create: create, update: update, } }; var game = new Phaser.Game(config); function preload () { console.log("this is preload"); } function create () { console.log("this is create"); } function update() { console.log("this is update"); } </script> </head> <body> </body> </html> |
1 2 3 4 5 6 7 8 9 10 |
var config = { type: Phaser.AUTO, width: 800, height: 600, scene: { preload: preload, create: create, update: update, } }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<!doctype html> <html lang="ja"> <head> <meta charset="UTF-8"> <script src="//cdn.jsdelivr.net/npm/phaser@3.17.0/dist/phaser.js"></script> <style> body { margin: 0; } </style> <script> var titleScene = new Phaser.Scene('titleScene'); titleScene.preload = function() { console.log("this is title preload"); }; titleScene.create = function() { console.log("this is title create"); this.scene.start('mainScene'); }; var mainScene = new Phaser.Scene('mainScene'); mainScene.preload = function() { console.log("this is main preload"); }; mainScene.create = function() { console.log("this is main create"); }; mainScene.update = function() { console.log("this is main update"); }; var config = { type: Phaser.AUTO, width: 800, height: 600, scene: [titleScene, mainScene] }; var game = new Phaser.Game(config); </script> </head> <body> </body> </html> |
1 2 3 4 5 6 7 8 |
var titleScene = new Phaser.Scene('titleScene'); titleScene.preload = function() { console.log("this is title preload"); }; titleScene.create = function() { console.log("this is title create"); this.scene.start('mainScene'); }; |
1 |
this.scene.start('mainScene'); |