Jump to content

How i can do collide everything inside on a layer with my character


Recommended Posts

Hi guys i have a tilemap with 4 layers(ground, water, roads, others) and a sprite with my character. how i do would for my character can collide with everything inside on others(layer),every layer use a different sprite, example ground use ground.png, water water.png etc, i have this code ( i use https://github.com/lean/phaser-es6-webpack):

/* globals __DEV__ */
import Phaser from 'phaser'
import Mushroom from '../sprites/Mushroom'
import Link from 'phaser-link'

export default class extends Phaser.State {
  super() {
  init () {}
  preload () {
    this.load.image('terrain', '../../assets/sprites/tileset_basic_terrain.png', 16, 16)
    this.load.image('this.others', '../../assets/sprites/tileset_other.png', 16, 16)
    this.load.image('water', '../../assets/sprites/tileset_water.png', 16, 16)
    this.load.tilemap('tilemap', '../../assets/map/overworld_01.json',null,Phaser.Tilemap.TILED_JSON)
    this.load.spritesheet('character', '../../assets/sprites/character.png', 16, 32, 1)

  create () {
    this.map = this.game.add.tilemap('tilemap')
    this.map.addTilesetImage('tileset_basic_terrain', 'terrain', 16, 16)
    this.map.addTilesetImage('tileset_other', 'this.others', 16, 16)
    this.map.addTilesetImage('tileset_water', 'water', 16, 16)

    this.ground = this.map.createLayer('Ground')

    this.water = this.map.createLayer('Water')

    this.others = this.map.createLayer('Others')
    this.roads = this.map.createLayer('Roads')
    this.map.setCollisionBetween(0,1000, true, this.others)
    this.physics.startSystem( Phaser.Physics.ARCADE )
    this.link = this.add.existing(new Link({
        game: this.game,
        key: 'character',
        controls: true,
  update() {
    this.game.physics.arcade.collide(this.link, this.others);
  render () {
    if (__DEV__) {
      //this.debug.body(this.player,16, 32)


But sometime when i try test the collision between the player and layer others, this don't work correctly, collide in a blank block in somewhere place for example left and top place, but in bottom and right place the collide work correctly. for create my map i use tilemap editor 1.0.3

Images of example:


there i can't move more to right:



there i can't move more to bottom:



there work correctly



Sorry for my bad english. and thanks


Link to comment
Share on other sites


  • Recently Browsing   0 members

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