Jump to content

Collision Issue


yigitozdemir
 Share

Recommended Posts

Hi Guys,

 

I recently started to html5 game development. I choose Phaser library to build games. After Java work for years i feel little bit weird :)

 

Here is my question. As i read in examples and tutorials, i created a tilemap example for testing. When i add y-axis gravity down-wards collision works but others not (i dont want any gravity) When i remove the gravity, there is no collision work.

 

here is my code:

var game = new Phaser.Game(500,500,Phaser.AUTO,'game');var layer;var map;var player;var cursors;var mainState = {    preload: function() {        this.game.stage.backgroundColor = '#FFFFFF';        game.load.tilemap('map','map.json',null,Phaser.Tilemap.TILED_JSON);        game.load.image('tiles','Images/tileset.png');        game.load.image('player', 'Images/blue.png');    },    create: function(){        game.physics.startSystem(Phaser.Physics.ARCADE);        map = game.add.tilemap('map');        map.addTilesetImage('tileset', 'tiles');        map.setCollision(1);        layer = map.createLayer("layer1");        layer.debug = true;        layer.resizeWorld();        player = game.add.sprite(62,62,'player');        game.physics.arcade.enable(player);        game.physics.enable(player, Phaser.Physics.ARCADE);        player.body.collideWorldBounds = true;        cursors = game.input.keyboard.createCursorKeys();        game.camera.follow(player);    },    collide: function(){        console.log('debug');    },    update: function(){        game.physics.arcade.collide(player, layer, mainState.collide, null, this);        player.body.velocity.x = 0;        if (cursors.up.isDown)        {            player.body.y -= 4;        }        else if (cursors.down.isDown)        {            player.body.y += 4;        }        if (cursors.left.isDown)        {            player.body.x -= 4;        }        else if (cursors.right.isDown)        {            player.body.x += 4;        }    },}game.state.add('main',mainState);game.state.start('main');

i just want to collide a block of map and the rectangle image that i cereated and dont move, nothing much :) But there is nothing shows up in console, so we now there is no collision.

 

What do you think about my problem? Can it survive?

 

Regards :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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