Advertisement
nPhoenix

Phaser 3 Scene test 2

Mar 26th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Scene = {};
  2.  
  3. var OverWorld = {},
  4.     Battle = {};
  5.  
  6. OverWorld.Extends = Phaser.Scene;
  7.  
  8. OverWorld.initialize = function () {
  9.     Phaser.Scene.call(this, {key: "overworld"});
  10. };
  11.  
  12. OverWorld.init = function (data) {
  13.     console.log("OverWorld Scene init", data);
  14.     this.data = data;
  15. };
  16.  
  17. OverWorld.preload = function () {
  18.     console.log("OverWorld Scene preload");
  19.     this.load.image("bunny", "bunny.png");
  20. };
  21.  
  22. OverWorld.create = function () {
  23.     console.log("OverWorld Scene create");
  24.     console.log("this.data", this.data);
  25.     this.bunny = this.add.sprite(200, 200, "bunny");
  26.    
  27.     console.log(this.game);
  28. };
  29.  
  30. OverWorld.update = function (time, delta) {
  31.    
  32.     //console.log(a, b);
  33.    
  34.     this.bunny.x += 10;
  35.     if (this.bunny.x >= 800)
  36.         this.bunny.x = 200;
  37. };
  38.  
  39. Scene.OverWorld = new Phaser.Class(OverWorld);
  40.  
  41. Battle.Extends = Phaser.Scene;
  42.  
  43. Battle.initialize = function () {
  44.     Phaser.Scene.call(this, {key: "battle"});
  45. };
  46.  
  47. Battle.init = function (data) {
  48.     console.log("Battle Scene init", data);
  49.     this.data = data;
  50. };
  51.  
  52. Battle.create = function (data) {
  53.     console.log("Battle Scene create");
  54.     this.scene.start("overworld", {xsd:123, abc:321});
  55. };
  56.  
  57. Scene.Battle = new Phaser.Class(Battle);
  58.  
  59. var config = {
  60.     type: Phaser.AUTO,
  61.     width: 800,
  62.     height: 600,
  63.     parent: "game",
  64.     autoStart: false
  65.     //scene: [ Scene.Battle, Scene.OverWorld ]
  66. };
  67.  
  68. var game = new Phaser.Game(config);
  69.  
  70. game.scene.add("battle", Scene.Battle);
  71. game.scene.add("overworld", Scene.OverWorld);
  72.  
  73. game.scene.start("battle", {abc: 123});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement