phaser icon indicating copy to clipboard operation
phaser copied to clipboard

matterjs attractor plugin not working with image

Open stathismor opened this issue 6 years ago • 2 comments

Version

  • Phaser Version: 3.22
  • Operating system: Linux
  • Browser: Firefox

Description

I cannot make matterjs attractor plugin work with a simple image or sprite. I can see that the example works with imageStack, but not with an image or a sprite. Tried looking at the code, but cannot see what makes imageStack special in this case.

Example Test Code

I modified the example just to have one image from imageStack and one normal image:

function create ()
{
    this.matter.world.setBounds();

    this.matter.add.image(0, 400, 'alien', null, {
        mass: 0.5,
        ignorePointer: true
    });

    this.matter.add.imageStack('alien', null, 0, 500, 1, 1, 0, 0, {
        mass: 0.5,
        ignorePointer: true
    });

    var sun = this.matter.add.image(400, 200, 'sun', null, {
        shape: {
            type: 'circle',
            radius: 64
        },
        plugin: {
            attractors: [
                function (bodyA, bodyB) {
                    return {
                        x: (bodyA.position.x - bodyB.position.x) * 0.000001,
                        y: (bodyA.position.y - bodyB.position.y) * 0.000001
                    };
                }
            ]
        }
    });

    this.matter.add.mouseSpring();
}

This makes only the alien from imageStack get attracted to the sun.

stathismor avatar May 22 '20 17:05 stathismor

I'm experiencing the exact same issue.

MickCoelho avatar Jul 02 '20 00:07 MickCoelho

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

The plugin had a bug which meant it failed to attract bodies that came before it in the World list. I fixed it to work on any body.

photonstorm avatar Jul 23 '20 17:07 photonstorm