Jump to content

No collision on the x axis


Chaosus
 Share

Recommended Posts

Hi, I tried to do exactly like the mapcolide phaser example, and it appears that I still have a big problem with the collision. Everything works fine, except for the x axis collisions, that are totally wrong. Try it yourself : http://phasertest.netai.net/

 

Yet, it's weird because I have barely exactly the same code than in the example, which is :

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });function preload() {    game.load.tilemap('mario', 'assets/tilemaps/maps/super_mario.json', null, Phaser.Tilemap.TILED_JSON);    game.load.image('tiles', 'assets/tilemaps/tiles/super_mario.png');    game.load.image('player', 'assets/sprites/phaser-dude.png');}var map;var tileset;var layer;var p;var cursors;function create() {    game.stage.backgroundColor = '#787878';    map = game.add.tilemap('mario');    map.addTilesetImage('SuperMarioBros-World1-1', 'tiles');    //  14 = ? block    // map.setCollisionBetween(14, 15);    map.setCollisionBetween(15, 16);    map.setCollisionBetween(20, 25);    map.setCollisionBetween(27, 29);    map.setCollision(40);        layer = map.createLayer('World1');    //  Un-comment this on to see the collision tiles    // layer.debug = true;    layer.resizeWorld();    p = game.add.sprite(32, 32, 'player');    game.physics.gravity.y = 250;    p.body.bounce.y = 0.2;    p.body.linearDamping = 1;    p.body.collideWorldBounds = true;    game.camera.follow(p);    cursors = game.input.keyboard.createCursorKeys();}function update() {    game.physics.collide(p, layer);    p.body.velocity.x = 0;    if (cursors.up.isDown)    {        if (p.body.onFloor())        {            p.body.velocity.y = -200;        }    }    if (cursors.left.isDown)    {        p.body.velocity.x = -150;    }    else if (cursors.right.isDown)    {        p.body.velocity.x = 150;    }}function render() {    game.debug.renderCameraInfo(game.camera, 420, 320);    game.debug.renderPhysicsBody(p.body);}

Thanks.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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