Sign in to follow this  
natanael zalazar

Help ! collision with layers

Recommended Posts

Hello, i have problems with my layers ...

 

This is my code

 

Mi player has

this.body.collideWorldBounds = true;
this.game.physics.arcade.enable(this);

 

Create

var self = this;
        self.game.physics.startSystem(Phaser.Physics.ARCADE);

self.map = self.game.add.tilemap('map');
        self.map.addTilesetImage('tileset');
        self.map.addTilesetImage('1556');
        self.map.addTilesetImage('1557');
        self.map.addTilesetImage('1558');
        self.map.addTilesetImage('1559');
        self.map.addTilesetImage('12021');
        self.map.addTilesetImage('8076');
        self.map.addTilesetImage('15118');
        self.map.addTilesetImage('15229');
        self.map.addTilesetImage('5001');
        
        self.maplayer1 = self.map.createLayer('Tile Layer 1');
        self.maplayer2 = self.map.createLayer('Tile Layer 2');
        self.maplayer3 = self.map.createLayer('Tile Layer 3');
        self.maplayer4 = self.map.createLayer('Tile Layer 4');

        self.map.setCollisionBetween(1, 10000, true, self.maplayer2);
        self.map.setCollisionBetween(1, 10000, true, self.maplayer3);
        self.map.setCollisionBetween(1, 10000, true, self.maplayer4);

self.maplayer1.inputEnabled = true;

        self.maplayer1.resizeWorld();
        self.maplayer2.resizeWorld();
        self.maplayer3.resizeWorld();
        self.maplayer3.resizeWorld();

const player = new Player({
            game: self.game,
            x: Math.floor((Math.random() * 300) + 1),
            y: Math.floor((Math.random() * 500) + 1),
            body: 'human_naked',
            nickname: 'nat' + Math.floor((Math.random() * 1000) + 1),
            head: 'elf_head_2',
        });

self.players.push(player);

 

 

And my update is

var self = this;
        self.game.physics.arcade.collide(self.maplayer2, self.players[0]);
        self.game.physics.arcade.collide(self.maplayer3, self.players[0]);
        self.game.physics.arcade.collide(self.maplayer4, self.players[0]);

 

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

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.