Jump to content

Player won't collide? (Tiled/Json-Map)


Recommended Posts

Hei i have an issue and i cant figure out what i'm doing wrong.


I have created a map with tiled and i added 2 tilesets. With the elements of the first tileset the player collides well. But with the elements of the second tileset it doesn't collide, it just goes trough the tiles.


Please i need help :)


Here's the Code:

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: preload, create: create, update: update});function preload(){        game.load.image('bonus', 'assets/bonus.png');    game.load.image('tileset', 'assets/tileset.png');    game.load.image('player', 'assets/player.png');    game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON);    }function create(){        game.physics.startSystem(Phaser.Physics.ARCADE);        this.map = game.add.tilemap('map');    this.map.addTilesetImage('tileset');    this.map.addTilesetImage('bonus');        this.layer = this.map.createLayer('Kachelebene 1');    this.layer.resizeWorld();    this.map.setCollision(1);        this.player = game.add.sprite(580, 480, 'player');    game.physics.arcade.enable(this.player);    this.player.anchor.setTo(0.5, 0.5);    this.player.body.gravity.y = 500;        this.cursor = game.input.keyboard.createCursorKeys();        game.camera.follow(this.player);    }    function update(){        game.physics.arcade.collide(this.player, this.layer);        if(this.cursor.left.isDown){                this.player.body.velocity.x = -200;                } else if(this.cursor.right.isDown){                this.player.body.velocity.x = 200;                } else {                this.player.body.velocity.x = 0;                }        if(this.cursor.up.isDown && this.player.body.onFloor()){                this.player.body.velocity.y = -300;             }    }

-sorry for my bad english.

Link to comment
Share on other sites

  • 2 weeks later...

  • Recently Browsing   0 members

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