cupcoffee Posted November 21, 2015 Share Posted November 21, 2015 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 generationthis.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 PhaserGame.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 More sharing options...
jmp909 Posted November 23, 2015 Share Posted November 23, 2015 Check your getLayer functions are returning the right layer.Also don't do that in the loop, cache the relevant layer outside the loop... You're probably making more calls than you need to Link to comment Share on other sites More sharing options...
Recommended Posts