• Content Count

  • Joined

  • Last visited

  • Days Won


Goshawk last won the day on April 11

Goshawk had the most liked content!

About Goshawk

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I saw an example somewhere but cannot find it now that I need it. Basically, I want to create a bitmap frame that scales to the size of the text it contains. I know there's a certain technique where the whole image is scaled apart from the corners which are left untouched. Does anyone know what this is called? Can anyone point me towards an example of how this is done in Phaser?
  2. Doh, it's in the examples. I can't believe I missed it: Collide Custom Bounds
  3. I have a sprite that I want to bounce within a box. I know how to collide sprites when their outside edges touch but how do I bounce a sprite within a constrained area?
  4. Thanks for the clear example.
  5. I am making a game based on 16x16 sprites which I want to scale to fit the scree. The gameboard is 160 pixels wide. The problem is, I cannot get the pixels to render sharply (as if I'd enlarge them using nearest neighbour resize in Photoshop). I have styled the game canvas like so: canvas { /*centre canvas*/ padding: 0px; margin: 0px; display:block; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); /*fit canvas to viewport*/ min-height: 100vh; max-height: 100vh; min-width: 100vw; max-width: 100vw; object-fit: cover; -ms-interpolation-mode: nearest-neighbor; // IE 7+ (non-standard property) image-rendering: -webkit-optimize-contrast; // Safari 6, UC Browser 9.9 image-rendering: -webkit-crisp-edges; // Safari 7+ image-rendering: -moz-crisp-edges; // Firefox 3.6+ image-rendering: -o-crisp-edges; // Opera 12 image-rendering: pixelated; // Chrome 41+ and Opera 26+ } I have a boot state with the following init method: export default class extends Phaser.State { init() { this.stage.backgroundColor = '#EDEEC9' this.smoothed = false this.fontsReady = false this.fontsLoaded = this.fontsLoaded.bind(this) this.scale.startFullScreen(true) // Display as fullscreen on devices that support fullscreen api this.game.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT this.stage.smoothed = false; } From what I can tell from this example `this.stage.smoothed` should ensure that the pixels renders crisply. However, they do not. What do I need to do to get my images to render sharp?
  6. As above. I set a flag when I want to end the game and I switch the scenes in `update()` update(){ ... if(this.gameEnded){ this.scene.start('Menu'); } } The presumption I've made is that putting it at the end of `update()` ensures that Phaser has done all the updating it needs to do before the scene is destroyed. I have a handful of timeouts and time events in the scene and I wonder if they were causing the problems -- essentially a race condition where the scene was destroyed before updates could be called on it. I haven't done any testing apart from playing the game but it hasn't crashed yet. Have you any timeouts or time events in your scene?
  7. I'm now setting a flag to true when I want to switch to the menu scene. The actual `this.scene.start('Menu')` call is now done at the end of `update()`. This seems to have fixed it. I'm sure I'll have a better understanding of what's going on when I become more familiar with the framework.
  8. Still unsure what's happening. The topmost error message points to this line: /** * The Scene that owns this plugin is shutting down. * We need to kill and reset all internal properties as well as stop listening to Scene events. * * @method Phaser.Physics.Arcade.ArcadePhysics#shutdown * @since 3.0.0 */ shutdown: function () { var eventEmitter = this.systems.events; eventEmitter.off('update', this.world.update, this.world); // <- this line
  9. I'm using the latest release. The reason I'm concerned about the memory usage is that both the cumulative increase in memory usage and the crashes occur when switching scenes. This leads me to believe I'm doing something wrong/not doing something I'm supposed to do. I'll blame the wine for leading me to misinterpret the memory usage timeline. Interestingly, I'm now using CANVAS instead of AUTO and the game has yet to crash.
  10. Not sure if it's connected but memory usage increases when switching scenes. Which leads me to suspect that I'm not switching scenes correctly as I'm creating new objects (sprites, audio, etc...) each time I start the game scene. I either need to make sure these are all destroyed when starting the menu scene or look at the examples to see where I'm going wrong. Any suggestions?
  11. My game is crashing infrequently. I have three scenes, `BootGame`, `PlayGame` and `Menu`. I switch scenes as follows: play_game(){ this.scene.start('PlayGame'); } The game goes back and forth between `PlayGame` and `Menu` but every now and again (about 1 in 50 times), the game crashes when switching scenes. The error in the console is: Uncaught TypeError: Cannot read property 'update' of null at ArcadePhysics.shutdown (project.bundle.js:148885) at EventEmitter.emit (project.bundle.js:2506) at Systems.shutdown (project.bundle.js:35059) at SceneManager.stop (project.bundle.js:68428) at SceneManager.processQueue (project.bundle.js:67563) at SceneManager.update (project.bundle.js:67822) at Game.step (project.bundle.js:119399) at TimeStep.step (project.bundle.js:122906) at step (project.bundle.js:57645) This happens so infrequently, I have no idea what's causing it at the moment other than it has something to do with changing scenes. Is there anything that I'm obviously doing wrong? Am I changing scenes correctly? Are some extra steps I need to take when changing scenes?
  12. Oh, yes. I'm probably overthinking this! Although I'm a little worried about the proliferation of variables in my game. I'm new to both JS and Phaser 3 so I've been prodding a lot as I learn.
  13. Though, I'm not sure it works like I think it does. If I scale the hero sprite directly afterwards: this.physics.world.colliders.getActive().find(function(i){ return i.name == 'platform_collider' }).destroy(); this.hero.scaleX = 2.0; ...I get an error: project.bundle.js:104510 Uncaught TypeError: Cannot read property 'destroy' of undefined I have no idea why at the moment. Any help in understanding this would be welcome. Edit: This mouthful works: this.physics.world.colliders.remove(this.physics.world.colliders.getActive().find(function(i){ return i.name == 'platform_collider' })); this.hero.scaleX = 2.0; whilst the functional `.destroy()` version doesn't. Why does `this.hero.scaleX = 2.0;` break it?
  14. In fact, since the factory returns the object, I can set a name on it when I create it: this.physics.add.collider(this.hero, this.platforms, this.collidedWithPlatform, false, this).name = 'platform_collider'; Then, if I want to destroy that particular collider only, I can do: this.physics.world.colliders.getActive().find(function(i){ return i.name == 'platform_collider' }).destroy();
  15. Thanks. I found another way which avoids the need of the variable. this.physics.world.colliders ...returns a process queue (`Phaser.Structs.ProcessQueue.<Phaser.Physics.Arcade.Collider>`). Calling: this.physics.world.colliders.destroy(); ...destroys the colliders in that queue.