setCollisionByProperty seems not to be working

Recommended Posts

Here's my create() function.

   create() {
      const map = this.make.tilemap({key: "level_map"});

      const tileset = map.addTilesetImage("Caves", "tiles");

      const walls  = map.createStaticLayer("walls", tileset, 0, 0);
      const decals = map.createStaticLayer("decals", tileset, 0, 0);

      // create player sprite
      this.player = this.physics.add.sprite(16*9, 16*23, "player");

      // set collitions tiles by property
      walls.setCollisionByProperty({collides: true});

      // show collision tiles with different color
      const debugGraphics = this.add.graphics().setAlpha(0.45);
      walls.renderDebug(debugGraphics, {
         tileColor: new Phaser.Display.Color(40, 255, 48, 255), // Color of non-colliding tiles
         collidingTileColor: new Phaser.Display.Color(243, 134, 48, 255), // Color of colliding tiles
         faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Color of colliding face edges

      // setup physics
      this.physics.add.collider(this.player, walls);

      // cursors
      this.cursors = this.input.keyboard.createCursorKeys();

      // camera
      this.camera = this.cameras.main;
      this.camera.setBounds(0, 0, map.widthInPixels, map.heightInPixels);

I load up a tilemap, read layers "walls" and "decals", set a collision by property and then add a collider of player to "walls". For me it seems that everything is ok. 

In Tiled I set up a "collides" bool variable and marked all impassible tiles as true, saved a level, exported JSON.. For debugging properties I even set up "walls.renderDebug" thing.

And of course after I launch the game I get a screen filled with green areas and my player falling down through a level.

One small note is that if I, instead of setCollisionByProperty use setCollisionBetween(1, 100) for example I do get some areas colored orange.

So, what am I doing wring in my code? In attachement there is my JSON file, maybe something is wrong with it.


Edited by talamask
added JSON with level

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.