• Content count

  • Joined

  • Last visited

About Anderberg

  • Rank
    Advanced Member

Contact Methods

  • Twitter

Recent Profile Visitors

290 profile views
  1. Finally I seem to have found it. In, at least Chrome, there is a memory leak bug when you try to stop and disconnect an AudioBufferSouceNode at the same time. This behaviour was introduced in Phaser with this commit: A fix that seems to work is to move the disconnect parts to the onendedhandler. if (this.externalNode){ this._sound.disconnect(this.externalNode);}else{ this._sound.disconnect(this.gainNode);}*if you force restart audio with the play function you might need another solution. Working demo:
  2. That issue sounds like it could be the cause. It does not happen in 2.3, but something could very well have changed in when creating sounds in 2.4 to get that bug. The reloading each time is intentional, it is to simulate switching between many more states where I cannot hold all the audio files decoded in the browser.
  3. I still haven't found a solution for this problem, so I created an isolated test case and hope that someone can confirm the same problem. v2.4.4 - v2.3.0 - v2.4.4 decode w/o play - - Open a task manager and watch the memory usage grow (chrome/webkit). What I have noticed so far: 1) It is somewhere between v2.3.0 and v2.4.0a when running web audio. 2) Only in Chrome on my desktop, and in Safari on the iPad, so I'm guessing it is webkit related. 3) Creating sound objects seems to be what keeps the memory stuck. I don't know how yet. I found this out by not creating a sound object in the states. Decoding is still done, but memory is freed when changing states. (Note: Decoding is what uses up a lot of memory. Decoding is done automatically if not specifically told not to when loading the audio. If you say so, decoding will be done when the sound is played instead, with the same effect.)
  4. To have the option of including audio decoding in the preload would be really nice (I know this has been mentioned before, but I think it is worth mentioning again and didn't see it in the feature list.)
  5. RedPanduzer: Even though you didn't find a solution for web audio it is somehow good to hear that I am not the only one with this problem My memory usage should peak at about 400-500MB (using web audio) and go back down to 250-300. At least that is what happened in earlier Phaser versions. Thanks for the tip about not using web audio. I will experiment a bit to see if it will fix it for me! I've read up before that audio tags can only play one at the time, but perhaps that has changed, I'll try it out none the less.
  6. Does anyone know how to unload and destroy audio files appropriately? I have about 12 MB of audio in my game, or about 15 minutes. I do not load all of them at one time, since this will break any mobile browser. So I load them in the states they are needed. About 4 MB is loaded at the same time. According to the Task Manager in chrome, the memory used by my game just keeps growing and growing, easily above 1000MB by changing states. (Browsers decode audio to lossless => memory use is high, regardless of file format and encoding.) In all states I have a shutdown function that destroys all the sounds and purges audio loaded in the cache. This is my current code (very similar to how cache is cleared when changing states, but I have some assets I use everywhere and don't want to remove): function clearCache () { // Purge sound. var key = this.sound._sounds.length; while (key--) { this.sound._sounds[key].destroy(true); } // Destroy "everything" in cache. for (var i = 0; i < this.cache._cacheMap.length; i++) { var cache = this.cache._cacheMap[i]; for (key in cache) { if (key !== '__default' && key !== '__missing' && this.cache._doNotDelete.indexOf(key) < 0) { if (cache[key].destroy) { cache[key].destroy(); } delete cache[key]; } } }}(Note: This problem did not occur in previous Phaser versions, so I am suspecting that some reference to the audio files are lingering, but can't find out where.) Also, if anyone has a good way of profiling and debugging browser audio, please share, I haven't found a good way to figure out where all this memory goes (Chrome heap profiler says that I use | 20MB).
  7. I've been pondering a solutions like yours, maybe that is the way to go for med too. The music will probably always be a single audio file in my case, so that audio object could be saved individually in some variable. Then you iterate over all the sounds that isn't that one when changing sound effect volume.
  8. toFixed will return a string, that is why you get contatenation instead of addition. (source: You want to use Math.floor( instead.
  9. Like all other games I have music and sound effects. However, right now I only have one volume control which changes the game.sound.volume, of course impacting all sounds. I would like to divide this into one volume control for the music and one for the sound effects. Does anyone know if this is built into Phaser somewhere? Or should I keep track of what audio objects that are music and which ones are sound effects? Is it possible to have two sound managers, one for music and one for sfx and would that even be appropriate? I'm happy for your input on the matter
  10. I took the liberty of changing your pen to expose the error: I've changed: * Game runs on CANVAS, not AUTO. The bug is not shown when you use webGL. * Added a tint to the ninja. (I also found that I created a codepen with the issue before:
  11. Hi Nicholls! Great that you took another look at it! I haven't been able to try your solution since my code has changed so much since this issue was reported. The tinting-then-changing-frame issue is still a problem in Phaser (Canvas only), so I am not quite positive that your solution actually fixes that. Is your sprite tinted? Are you able to change frame without re-tinting it?
  12. Thanks for the help! I will start out using the arcade system and have quite quadratic sprites or smaller bounding boxes. Then I might add spheres and perhaps even more advanced like insaneHero's code if it is necessary. I did try out some P2, but didn't get very far into it. The fps on my mobile dropped almost 20, with only about 20 bullets on screen. But it could probably be improved, for example by turning off impacts and using onBeginContact (as suggested here: While searching I found this page which might help those coming here for answers: Now I will try to create lasers for the game, which will be rotated. So I thought I should try out parts of the raycasting example from the link above.
  13. gregmax17: Certainly, I will try to stick mainly to rectangles as hit areas and then work my way upwards in the number of bodies. lewster32: Great idea! This is probably the approach I will use. I will however have to recalculate the boxes as the object rotates, I'll google some mathematics for how to do that.
  14. I am developing a shoot em up where I of course have to detect collisions/overlaps between sprites. Since there will be a lot of bullets on the screen, I need to do really efficient collision detection. No physics such as gravity, friction or the like is necessary. I started out using the Arcade system, but since it cannot handle rotated bodies I have to search for something else (for me it was really confusing that the Arcade physics has several properties that sound like it can actually do rotation, when the bodies cannot be rotated). Anyway, I am trying out P2 instead. First of all, is P2 the best to use? It seems a bit "heavy" for what I want to do. If I need P2, what ways are there to cut down the computations that I do not need? I have set these properties, are there any more to look into?game.physics.p2.applyDamping = false;game.physics.p2.applyGravity = false;game.physics.p2.applySpringForces = false;game.physics.p2.solveConstraints = false;game.physics.p2.setImpactEvents(true); Thankful for any input
  15. I can see that Pixi has an issue with this that one might want to monitor: