Arcade vs. MatterJS performance

Hi Everyone,

Just did a bit of benchmarking with Chrome Dev tools to test performance on a large platform level:

Here’s a 30 second snapshot with using Arcade physics:

And the same thing with MatterJS:

… and my fan was spinning so furiously I thought my laptop was going to take flight!

So, the bottom line is: Don’t use MatterJS unless you absolutely can’t fake it using Arcade.

The only reason I’ve needed to consider MatterJS however has so far been for sloped platforms - which doesn’t seem to have an Arcade implementation?

1 Like

Hi
I need sloped platforms too, but matter is a no go for me, so i don’t use slope platforms until i found a solution to fake it with arcade and tiled maps.

Thanks @BlunT76!

Yes, just looking at faking sloping tiles with Arcade physics at the moment. This very rudimentary code for left-facing 45 degree slopes for 16x16 tiles is working just fine - I’m going to try and generalise it for different angles next:

this.slopeGroup = this.physics.add.staticGroup();
    platforms.forEachTile(tile => {
      if (tile.index === 6) {
        const x = tile.getCenterX();
        const y = tile.getCenterY();
        const slope = this.slopeGroup.create(x, y, "slope_45_Left");
        platforms.removeTileAt(tile.x, tile.y);
      }
    });

    //Slope collision with the player
    const intersectLeft45Slope = (player, slope) => {
      const dx = player.x + player.body.halfWidth - slope.x;
      player.y =
        slope.y -
        slope.body.height -
        10 -
        player.body.halfHeight -
        slope.body.halfHeight +
        dx;

      //Set velocity to zero
      player.body.velocity.y = 0;
    };
    const isInsideSlope = (player, slope) => {
      //Only check for a collision if the bottom of the player is
      //inside the slope - prevents "jumping" when the player is
      //at the slope apex
      return (
        player.y + player.body.halfHeight + 1 > slope.y - slope.body.halfHeight
      );
    };

    //Collision between player and slopes
    this.physics.add.overlap(
      this.player,
      this.slopeGroup,
      intersectLeft45Slope,
      isInsideSlope,
      this
    );

(…The “10” in there is just a mystery number I needed to add to smooth it out - still need to understand that part better…)

1 Like

Thanks,
I’ll give it a try