Jump to content

Can't get generated tilemap working with collision


cupcoffee
 Share

Recommended Posts

So i've been trying to generate a tilemap and then let my player sprite collide with the tilelayer. Both bodies are getting rendered by the debug renderer as seen in this screenshot.

 

http://puu.sh/ltmsa/4e3ef1765f.png

 

In the picture the player sprite is at the bottom of the layer thus being held in place by the collideWorldBounds.

The sprite should be blocked by the tilelayer even though both bodies are there, there's no collision.

 

Now on to the code:

 

Initialization / World generation

this.tileMap = Game.add.tilemap();this.tileMap.addTilesetImage("terrain", "terrain", 72, 72, 0, 0);this.tileLayer = this.tileMap.create("world", 100, 10, 70, 70);this.tileLayer.debug = true;for (var x = 0; x < this.tileMap.width; x++) {    // Tile.GRASS.guid = 9    this.tileMap.fill(Tile.GRASS.guid, x, this.tileMap.height - 5, 1, 1, "world");}this.tileMap.setCollision(Tile.GRASS.guid, true, this.tileLayer);Game.physics.startSystem(Phaser.Physics.ARCADE);Game.physics.arcade.gravity.y = 250;

The player sprite being added to the gameloop:

getBody() and getSprite() obviously return the sprite and body instances of Phaser

Game.physics.enable(entity.getSprite());entity.getBody().bounce.y = 0.2;entity.getBody().linearDamping = 1;entity.getBody().collideWorldBounds = true;

Every update:

this.entities.forEach(entity => {    Game.physics.arcade.collide(entity.getSprite(), this.tileMap.layers[this.tileMap.getLayer("world")]);    entity.update();        });
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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