Jump to content

Collision breaks when loading in a Tiled tilemap


zazazayou
 Share

Recommended Posts

I m building a little platformer-type game and am having this problem: When the player is moving really fast, (basically when he falls a large distance) he no longer collides with stuff, and falls right through the floor. This problem comes up when I switch from making regular sprites in a group for floors and platforms, to loading in a tilemap from Tiled.

 

I also notice a change, which is my only hint that something is working differently with the physics - the sprite's body.touching property no longer reads, and instead body.blocked now reads. So for example, if I let the player jump only if player.touching.down is true, I have to switch this condition when using the Tiled tilemap to player.blocked.down, because touching becomes always false. I don't really know phaser well enough to know why this is, but I just know its weird.

here is how my code was before, when just making a group of sprites for platforms:

    this.platforms = this.add.group();
            this.platforms.enableBody = true;

            var element;
            platformData.forEach(function( platform ){
                element = this.platforms.create(platform.x, platform.y, 'green');
                element.scale.setTo(platform.scaleX, platform.scaleY);
            }, this);
            this.platforms.setAll('body.immovable', true); // so they don't fall
            this.platforms.setAll('body.allowGravity', false); // so they can't be moved by other bodies

 

and here is how it is when I load the map from Tiled:

            //create a tilemap object
            this.map = this.add.tilemap('level1');
        
            //join the tile images to the json data
            this.map.addTilesetImage('tilesheet', 'gameTiles');

            //create tile layers
            this.tileLayer = this.map.createLayer('tileLayer');

            //collision layer should be collisionLayer
            this.map.setCollisionBetween(1, 1, true, 'tileLayer');

            //resize the world to fit the layer
            this.tileLayer.resizeWorld();

 

And in update():

    this.game.physics.arcade.collide(this.player, this.tileLayer);

 

So it's weird, it collides just fine in every case, except when loading stuff from Tiled and moving really fast, and I don't really know why in one case bodies touch and in the other case bodies block, or what the difference really is supposed to mean.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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