nPhoenix

Phaser Scene (without ES6)

Jul 11th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const A = {};
  2.  
  3. A.Extends = Phaser.Scene;
  4.  
  5. A.initialize = function () {
  6.     Phaser.Scene.call(this, {key: "sceneA"});
  7. };
  8.  
  9. A.init = function (data) {
  10.     console.log("Scene A Init", data);
  11.     this.socket = data.socket;
  12. };
  13.  
  14. A.create = function () {
  15.     console.log("Scene A");
  16.     this.socket.emit("lol", 123);
  17. };
  18.  
  19. const SceneA = new Phaser.Class(A);
  20.  
  21. const Battle = {};
  22.  
  23. Battle.Extends = Phaser.Scene;
  24.  
  25. Battle.initialize = function () {
  26.     Phaser.Scene.call(this, {key: "battle"});
  27. };
  28.  
  29. Battle.create = function () {
  30.     console.log("Battle Scene");
  31.     //this.scene.start("sceneA", {xsd:123, abc:321});
  32. };
  33.  
  34. const BattleScene = new Phaser.Class(Battle);
  35.  
  36. const config = {
  37.     type: Phaser.AUTO,
  38.     autoStart: false,
  39.     width: 800,
  40.     height: 600,
  41.     parent: "game",
  42. };
  43.  
  44. const gameInstance = new Phaser.Game(config);
  45.  
  46. gameInstance.scene.add("sceneA", SceneA);
  47. gameInstance.scene.add("battle", BattleScene);
  48.  
  49. gameInstance.scene.start("sceneA", {
  50.     socket: socket,
  51.     parametros: "pra passar pra scene"
  52. });
Add Comment
Please, Sign In to add comment