Jump to content

space inbetween


mrxj88
 Share

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() {
        game.physics.startSystem(Phaser.Physics.ARCADE);
        map = game.add.tilemap('map');
        map.addTilesetImage('set1', 'tiles');
        layer = map.createLayer('background');
        layer = map.createLayer('walls');
        layer.resizeWorld();
        
        map.setCollisionBetween(1, 3000, true, 'walls')
        
        
        
        player = game.add.sprite(150,150, 'player');
        player.scale.setTo(0.2,0.2);
        
        game.physics.enable(player)
      
        cursors = game.input.keyboard.createCursorKeys();
        game.camera.follow(player);
        
        
    },
    
    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;
            }

    }   

    
};

 

Untitled.png

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

 Share

  • Recently Browsing   0 members

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