Jump to content

two newbie questions (collisions and scale related crash)


Recommended Posts


Just checking out phaser3. Currently I'm trying to write a function that makes sparks appear when two objects collide.

I'm at the point where I can drag and drop two objects, and when they hit I have some spark sprites appear near the collision coordinates. Two problems though:

1) As there is no space for the sparks at the exact coordinates, matter moves the sparks quite a bit above the colliding objects, which looks silly. I think the best way would be to disable the collision between sparks and the objects. If somebody would have advice on how I can tell the sparks to not care about each other or the two colliding objects, that would be great. Of course it seems that I could just disable the physics for the sparks alltogether, but I want them to be effected by gravity and bounce back from walls and maybe other objects.
2) I want the sparks to become smaller and then vanish, so I wrote this:

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);

Instead of "remove spark" I have to destroy there the object (still have to look up how that works). The problem is: this works for a second or so but then crashed the browser tab. I don't get why it should crash the tab (scale starts with a value of 1).

Thanks for any advice. :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...