Jump to content

Collision problem


tarnasm
 Share

Recommended Posts

Hi, 

I have problem with collision in my simple platformer game.  I have map loaded with a JSON file. My character collides only on the top of blocks. I attach my awful image bellow what simmulate my problem. (red lines simmulate's no collision area, on blue lines my player collides and stand into platform.

var game = new Phaser.Game(640, 640, Phaser.CANVAS, 'main', {
    preload: preload,
    create: create,
    update: update,
    render: render
});

var player ;
var map;
var layer;
var key;

function preload() {
    game.physics.startSystem(Phaser.Physics.ARCADE)
    game.load.tilemap('map', 'assets/map.json',null, Phaser.Tilemap.TILED_JSON);
    game.load.image('mainTileSet', 'assets/maps/tileSet.png');
    // game.load.spritesheet('player', 'assets/sprites/tileSet.png',0,0);
}

function create() {
    map = game.add.tilemap('map');
    map.addTilesetImage('mainTileSet');
    map.setCollisionBetween(1, 180);

    layer = map.createLayer('mainLayer');
    layer.resizeWorld();
    layer.debug = true;

    player = game.add.sprite(0,0,'player');
    game.physics.enable(player);
    game.camera.follow(player);
    player.body.collideWorldBounds = true;
    player.body.gravity.y = 600;

    key = game.input.keyboard.createCursorKeys();
}
function update() {
    game.physics.arcade.collide(player, layer);

    if(key.left.isDown){
        player.x -= 7
    }if(key.right.isDown){
        player.x += 7;
    }if(key.up.isDown){
        player.y -= 15;
    }if(key.down.isDown){
        player.y += 7;
    }
}

function render () {
    game.debug.body(player);
}

 

export.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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