Skip to content

matterjs attractor plugin not working with image #5160

@stathismor

Description

@stathismor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions