Jump to content

space inbetween


Recommended Posts

I have a space in between my player and the tiles. i want the player to be able to touch the wall not have a space between him and the wall... here is a picture of what i mean. And here is the code im using:

var map; 
var layer;
var player;
var cursor;

var Game = {
    preload: function() {
        game.load.image('player', 'assets/player.png');
        game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON);
        game.load.image('tiles', 'assets/dun.png');
    create: function() {
        map = game.add.tilemap('map');
        map.addTilesetImage('set1', 'tiles');
        layer = map.createLayer('background');
        layer = map.createLayer('walls');
        map.setCollisionBetween(1, 3000, true, 'walls')
        player = game.add.sprite(150,150, 'player');
        cursors = game.input.keyboard.createCursorKeys();
    update: function() {
        game.physics.arcade.collide(player, layer);
        player.body.velocity.x = 0
        player.body.velocity.y = 0

        if (cursors.left.isDown)
                player.body.velocity.x = -150;
        else if (cursors.right.isDown)
                player.body.velocity.x = 150;
        if (cursors.up.isDown)
                player.body.velocity.y = 150;
        else if (cursors.down.isDown)
                player.body.velocity.y = -150;





Link to comment
Share on other sites

2 hours ago, phreaknation said:

might be that your sprites are not aligned properly. I would turn on debugging for such. You can see a demo of debugging in the phaser examples. Take a screenshot with debugging on which would be more helpful

Not sure if this is what you meant but i attached a picture with the debug for sprite. thanks again for your help

download (2).png

Link to comment
Share on other sites


  • Recently Browsing   0 members

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