Jump to content

Collisions with tiled


Recommended Posts

So i am trying to create a small map with tiled and implement it into phaser. But the collision between the map and the sprite im using as a player doesnt seem to work

Here is my code:

Platformer.Main = function(game){
    var map;
    var layer;
    var layer2;
    var layer3;

Platformer.Main.prototype = {
    preload: function(){
    create: function(){
        //map = this.game.add.image(0, 0, 'map');
        //map.width = 1280;
        //map.height = 3800;
		map = game.add.tilemap('firstLevel');

        map.addTilesetImage('object- layer', 'groundlayer');
        map.setCollisionBetween(15, 16);
        map.setCollisionBetween(20, 25);
        map.setCollisionBetween(27, 29);
        layer2 = map.createLayer('Background');
        layer3 = map.createLayer('Background2')
        layer = map.createLayer('Tile Layer 1');
        this.goUp = game.input.keyboard.addKey(Phaser.Keyboard.UP);
        this.goDown = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
        this.sprite = this.game.add.sprite(50, 250, 'player');
        game.physics.enable(this.sprite, Phaser.Physics.ARCADE);
        this.sprite.inputEnabled = true;
        this.sprite.body.collideWorldBounds = true;
    update: function() {
        game.physics.arcade.collide(this.sprite, layer);
        game.physics.arcade.collide(this.sprite, layer2);
            this.sprite.body.velocity.x = 0;
            this.sprite.body.velocity.y = 0;
        } else {
            game.physics.arcade.moveToPointer(this.sprite, 200);
        if (Phaser.Rectangle.contains(this.sprite.body, game.input.x, game.input.y))
            this.sprite.body.velocity.setTo(0, 0);

Im trying to get the player to collide with some rocks i have in my map. Those rocks are on layer and layer2 which im trying to collide with but it doest work.

It also gives me this error

Phaser.Tileset - image tile area is not an even multiple of tile size

I dont really know how to fix it :(

But im using spritesheets with more than 1 images on them and they are all 32x32 px.

And i have really never understood what the map.setCollisionBetween is doing thats why there is so many of them in there

Ty for any help :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

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