Jump to content

Tilemap: when player collides with platforms he cannot jump upwards


Viktoria
 Share

Recommended Posts

I have implemented tilemap from json file made in Tiled. It works fine. All platforms are shown. But then one issue occurs:

when player jumps on a platform it collides with it(ok), but then he cannot jump upwards.

 preload(){
        this.load.json('level','src/scenes/levels.json');
        this.load.image('ground','src/assets/plattformBigLevel2.png');
        this.load.image('background','src/assets/backgroundLevel2_4000.png');
        this.load.image('platform','src/assets/platformSmallLevel2.png');
        this.load.tilemapTiledJSON('map', 'src/assets/tiled/Level2.json');
        this.load.spritesheet('player','src/assets/bug.png',{ frameWidth: 55, frameHeight: 56 });
    }
    create(){
        //background
        this.image = this.add.image(2000,600,'background');

        //create a big platform
        this.platforms = this.physics.add.staticGroup();
        this.platforms.create(2000, 568,'ground');
        
        //create platforms
        this.map = this.make.tilemap({ key: 'map' });
        this.tiles = this.map.addTilesetImage('platformSmallLevel2', 'platform');
        this.layer = this.map.createStaticLayer(0, this.tiles, 0, 0);
        this.layer.setCollisionByProperty({ collide: true });

        let player_config = {
        	x: this.levelData.playerStart.x,
            y: this.levelData.playerStart.y,
            name: this.player_type,
            lives: this.player_lives,
            cursors: this.input.keyboard.createCursorKeys()
        }

        this.player = new Player(this, player_config);
        this.player.setCollideWorldBounds(true);
        this.physics.add.collider( this.player,this.platforms);
        this.physics.add.collider(this.player, this.layer);


        }

 

Link to comment
Share on other sites

I have resolved the issue. The problem was that while jumping on a platform imported from json, the collision worked and the player could jump on the platform. But then it doesnt recognised the platform as the floor and the property sprite.body.touching.down was set to false. 

I just added the function to the collision between player and platforms in wich I specified that sprite.body.touching.down should be equal to true. And it worked then????

function collidePlatforms(player,layer){

            this.player.body.touching.down = true;

        }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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