Couple beginner questions (collisions, performance, crash, removal)

Hi.
I began yesterday with looking into phaser, and I got a couple of questions. It would be great if anybody could give me some advice. :slight_smile:

  1. Performance. Is great for me everywhere, except for Chrome (Version 71.0.3578.98) on my MacBook. On any other browser on the MacBook things work well, also on my Android phone and on my Windows PC. The Chrome on my old Android phone has a far better performance than the Chrome on my MacBook. The problem seems to show up with any Phaser3 application making use of matter.js (all matter js examples for phaser3 were slow, other examples (like arcade physics) went smoothly). Is that a known problem? Is there a fix?

  2. I’m writing some functions that have "sparks (small glowing objects) appear when two objects collide. So far that works, I get sparks spawning and flying around when the objects hit each other. However, the sparks are not spawning at the correct location, I assume because matter considers that location already as being taken up by the colliding objects, so it spawns the sparks someplace else. What would the best way be to fix that? To me, it seems that it would be best to have the sparks not check collision with those two objects or with each other. Can I somehow tell matter js to have the sparks ignore certain other objects regarding collisions?

  3. I want the sparks to shrink and then vanish. So I put all the spark objects in an array and iterate through it (sorry, didn’t find here code tags):

function update() {
for(var i = 0; i < particles.length; i++) {
var scale = particles[i].scaleX;
if(scale < 0.5) {
//remove spark
}
else {
particles[i].setScale(scale - 0.01);
}
}
}

Basically, each object in the particles array is having it’s scale reduced until the scale is smaller than 0.5 at which point nothing happens right now (it’s ignored). The problem is that crashes the app. It runs for a second, and then the tab doesn’t react anymore (I don’t know if it’s caught in a loop or crashes or something).
I don’t know where the problem is. If I set the scale to a fixed amount in the “setScale” line, then that works. But if it depends on the last scale setting, it crashes quickly. I thought that at some point maybe the “scale” variable contains something that’s not a number, if something is not found, but that doesn’t make any sense and when creating an output the values always seemed to be correct. Any help? :slight_smile:

  1. How do I delete an object in a phaser3 matter world? I think the last attempt was something like: this.world.remove(particles[i]) or this.matter.remove() or something like that (I will put in here the correct code I used, currently having no access to it) to remove a certain particle object (and splicing it from the array). Doesn’t work. I don’t get an error message. The correct object is targeted and it’s not moved anymore, so somewhere it was removed, but it’s still visible on the screen. Do I have to refresh it?

Thanks for any help. :slight_smile:

Hey @Fnorglour, first of all welcome :slight_smile:

About you performance issue: i’m using windows 10 and i always used chrome while developing with phaser. I didn’t notice any performace issue about matterjs related examples. Maybe you can take a copy of phaser3-examples repo and work on localhost and try it out?

For sparks what i can say is use a pool of sparks, instead of removing and re-creating new sparks use the ones you already have. maybe you can go to examples search for “pool” or check this example that i find.

Instead of using your own way of particles, use examples about particles on https://labs.phaser.io/ and believe me there are a lot’s of examples about “particles”.

I’m not an expert about matterjs physics but as far as i know gameboject.destroy(); should work.
which also have an example on examples-website :slight_smile:

Please do follow for future questions. Have a nice day

Thanks a lot for the indepth reply. I"ll check that out this weekend when I have more time. :slight_smile: