Jump to content

How to make my sprite collide with tiles using MatterJS?


roberto257
 Share

Recommended Posts

I am creating a platformer with Phaser3 and I am using Matter for my physics engine. I have loaded my tilemap/set into the world, however, I don't know if the collisions are working because since I have added in this code, my sprite has disappeared. Why is this? How do I get my sprite to appear again so that I can make sure he collides with the tiles?

 //Create tilemap
        const map = this.make.tilemap({key: 'map'});
        //Create tileset
        const tileset = map.addTilesetImage('tiles');
        const platforms = map.createDynamicLayer(0, tileset, 0, 0);
        map.setCollisionByExclusion([-1, 0]);
        this.matter.world.convertTilemapLayer(platforms);
        //Update the game at 30Hz
        this.matter.world.update30Hz();

        //Get hitboxes
        this.shapes = this.cache.json.get('shapes');

        //Set boundaries for physics
        this.matter.world.setBounds(0, 0, game.config.width, 750);

        //Player
        this.hero = this.matter.add.sprite(0, 0, 'sheet', 'run_right/0013', {shape: this.shapes.s0013});
        //Don't want him rotating in the air
        this.hero.setFixedRotation();
        //Set our variable to do calculations
        heroSize = this.hero.width;

 

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

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