Jump to content

Multipe MatterSprites in a Matter Compound


AdrianoLobo
 Share

Recommended Posts

image.png.1d40f3f421da76db0b5220ebb317b3b8.png

Hi, I want to create this module, it's composed with 4 connectors and a main module. I created each using the:

this.scene.matter.add.sprite

I would like to be able to batch them togheter and simply call: module.setPosition(x, y) to move all of it. It would me nice too (but not required) if I was able to batch multiple modules to create a space station and be able to move everything.

I Tried with Matter Compound Bodies, but it seams that it can only compound matterjs pure bodies, not those with sprites attached to it. * I followed this example: http://labs.phaser.io/edit.html?src=src\game objects\tilemap\collision\matter platformer with wall jumping.js

I saw the new container feature but I dont know if it supports physics objects nor I was able to test it with the container branch.

Can you guys help me pointing to a direction?

Link to comment
Share on other sites

  • 4 months later...

You can add matter.js bodies to phaser containers in phaser 3 this way:

let container = scene.add.container(x, y);
let matterEnabledContainer = scene.matter.add.gameObject(this.container);
let matterBody = ... // setup matter.js-body
matterEnabledContainer.setExistingBody(matterBody);

 

Link to comment
Share on other sites

  • 1 year later...
mpoundBody = Body.create({
      parts: [mainBody, this.sensors.bottom, this.sensors.left, this.sensors.right],
      frictionStatic: 0,
      frictionAir: 0.02,
      friction: 0.1
    });
    this.sprite
      .setExistingBody(compoundBody)
      .setScale(2)
      .setFixedRotation() // Sets inertia to infinity so the player can't rotate
      .setPosition(x, y);
  }

based on the turoial - when I try to setExistingBody(compoundBody) I get this error

Argument of type 'Body' is not assignable to parameter of type 'BodyType'.
  Type 'Body' is missing the following properties from type 'BodyType': positionImpulse, previousPositionImpulse, constraintImpulse, totalContacts, and 10 more.ts(2345)
Edited by samme
format
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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