fariazz

Members
  • Content Count

    120
  • Joined

  • Last visited

Everything posted by fariazz

  1. Thanks that worked! If it helps anyone, this is how you can then retrieve the loaded object: // in preload() this.load.json('levelData', 'assets/level.json'); // in create() let data = this.cache.json.get('levelData');
  2. I'm using multiple scenes on a game, I'm using a scene (each one in it's own file) for the following: - Game itself - home screen - loading screen - a "boot" scene where I load the logo that I want to show in the loading screen I'm using mainly in ES5 and loading the files in this manner: <!-- index.html --> <script src="js/scenes/bootScene.js"></script> <script src="js/scenes/loadingScene.js"></script> <script src="js/scenes/homeScene.js"></script> <script src="js/scenes/gameScene.js"></script> <script src="js/main.js"></script> Each scene file looks like so: // create a new scene let homeScene = new Phaser.Scene('Home'); homeScene.create = function(){ // game background, with active input let bg = this.add.sprite(0, 0, 'backyard').setInteractive(); bg.setOrigin(0, 0); ETC... Adding them to my game like so: // our game's configuration let config = { type: Phaser.AUTO, width: 360, height: 640, scene: [bootScene, loadingScene, homeScene, gameScene], title: 'Virtual Pet', pixelArt: false, backgroundColor: 'ffffff' }; // create the game, and pass it the configuration let game = new Phaser.Game(config); Note I'm just loading my scenes in global variables, yes I'm polluting the global scope but I don't care. If you want to do it more elegantly you can load them in individual commonJS modules or ES6 modules, in my case I don't want to install 1000 node.js packages just to run the game so I'm doing it a bit old school.
  3. I think both are good options. Phaser 2 is a production-ready, mature frameworks that's been used professionally in all platforms. Phaser 3 on the other hand is just getting started, and as @blade2xs pointed out, the doc and examples are a bit behind. However, Phaser 3 is definitely mature enough to be used in production, you'll just have to do more work when it comes to finding answers. Phaser 3 offers significant performance improvements over Phaser 2. Also lots of new features which might be relevant to your game, more clean code and the option to code in ES6 all along the way. If you need to produce a game in a short period of time I'd suggest Phaser 2, if you want to learn and build skills I'd suggest Phaser 3 as the documentation and whatnot will catch up soon enough.
  4. All the assets are cached between scenes. If you load an asset in Scene A, you can then create say sprites from it in Scene B.
  5. Never mind! Found the answer in the Phaser newsletter:
  6. I'm looking at creating a loading screen, followed by a home screen, and the game screen. For that, I was thinking of using a Scene for each. My question is, if I do the preloading of the assets in the first scene (loading screen), and then move to the home scene, will the assets be available and cached between scenes? or does each scene need to load it's own assets?
  7. Does anyone know how to load a json file in the preload method in Phaser 3? The JSON folder of the examples in the Loader class are empty so I'm a bit stuck: http://labs.phaser.io/index.html?dir=loader/json/&q=
  8. I was wondering if it's expected behavior that camera effects are not reset when a scene is restarted. The following code will fade out, and the screen will remain black after the scene is restarted: gameScene.create = function() { // create a sprite let bg = this.add.sprite(100, 100, 'treasure'); // fade out this.cameras.main.fade(1000); // restart the scene this.time.delayedCall(2000, function() { this.scene.restart(); }, [], this); What I'm adding at the moment is `this.cameras.main.resetFX();` when initiating a scene in order to have the view back, but it kind of feels like the camera subsystem should refresh as well when using `this.scene.restart()`.
  9. fariazz

    Resetting a scene

    this.scene.restart(); works in Phaser 3.4
  10. I can confirm this is fixed on my end when using Phaser 3.4 for the `restart` method, however not when using the `rebootScene` method. The following code works fine on my end (sprites get cleared after scene restarting): // called once after the preload ends gameScene.create = function() { // create sprites at random let sprite1 = this.add.sprite(Math.random() * 400, Math.random() * 400, 'treasure'); let sprite2 = this.add.sprite(Math.random() * 400, Math.random() * 400, 'treasure'); let sprite3 = this.add.sprite(Math.random() * 400, Math.random() * 400, 'treasure'); let sprite4 = this.add.sprite(Math.random() * 400, Math.random() * 400, 'treasure'); this.time.delayedCall(3000, function() { this.scene.restart(); }, [], this); }; If instead of using `this.scene.restart()` I type `this.scene.manager.bootScene(this);`, the sprites don't get cleared after scene rebooting - they just accumulate on the screen. Not sure if that's the intended behavior of bootScene but thought it'd be good to mention it.
  11. Using this.scene.restart() unfortunately still doesn't solve the issue. Sprites are still not cleaned from the scene. Just tested building from the latest master branch commit:
  12. There is a new Scene manager restart() method coming in Phaser 3.4: https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md#new-features Will give this a try tomorrow
  13. I'm with you. The main thing I want to know is if we are doing it right but there is a bug in how scenes are being rebooted, or if we are doing it wrong and missing something important.
  14. That's strange to hear, Brackets works well on my end for Phaser. I prefer turning the auto-reload feature off and refresh manually. Another option for a web server is to install Node.js and the http-server package: 1) download and install Node.js 2) on command line, install the http-server package globally: npm install http-server -g 3) navigate to the folder where your Phaser project is located, type: http-server , that will launch a local web server for that folder
  15. Hi all, I'm trying to restart a scene but as you can see in this video, rebooting a scene doesn't get rid of the sprites of the scene: I was wondering if I'm making a mistake on how I'm restarting the scene, or if this is a bug and I should open a Github issue. Any help would be much appreciated!
  16. Good point! Option 2 also uses a for loop ( Phaser.Structs.Set#each )
  17. So far I've encountered different options and was wondering if there is any of them that should be preferred or is better practice (I'm feeling inclined for 3, but I might be missing something). All three work (tested): // option 1 Phaser.Actions.Call(this.enemies.getChildren(), function(enemy) { enemy.speed = Math.random() * 2 + 1; }, this); // option 2 this.enemies.children.each(function(enemy) { enemy.speed = Math.random() * 2 + 1; }, this); // option 3, native js this.enemies.getChildren().forEach(function(enemy) { enemy.speed = Math.random() * 2 + 1; }, this);
  18. I just published a tutorial that is aimed to be a starting point for new developers who want to start with Phaser 3, I tried to write some notes as well for Phaser 2 devs about some key differences: https://gamedevacademy.org/phaser-3-tutorial/ Hope you find it helpful!
  19. Hi everyone, just wanted to share my tutorial on how to make a simple frogger-style game in Phaser 3 (including some camera shake and fadeout effect) Hope you like it! How to make a game in Phaser 3
  20. Thanks for the quick response!
  21. I'm trying to get my head around the scene life-cycle and main methods. I understand render is called (aims at) 60 fps. What's the frequency/time-step of update?
  22. Had a look at Phaser.GameObjects.Group#createFromConfig but couldn't think of an easy way to add something like what scenes have: if (sceneConfig.hasOwnProperty('extend')) { for (var propertyKey in sceneConfig.extend) { newScene[propertyKey] = sceneConfig.extend[propertyKey]; } } But also I'm not fully convinced this should be added. I kind of thought that it would be nice to have but then easily added sprite custom properties using Call on the group object in my game: Phaser.Actions.Call(this.enemies.getChildren(), function(enemy) { enemy.speed = Math.random() * 2 + 1; }, this); Maybe it's best not to add so many things and see what common use patterns are emerging first.
  23. Phaser 3 is out and we are looking for motivated individuals to create engaging tutorials for this new framework, for our website GameDev Academy. To get an idea of what we are after, have a look at our Phaser 2 tutorials. You can either build a new mini-game, or take any of our Phaser 2 examples and try to port it in Phaser 3 - we are quite open when it comes to topics here and would love to hear what you would like to explore. This is a paid, freelancing position. We are flexible in terms of output, however we do want you to commit to at least 1 tutorial per month. APPLY HERE