mrxj88 Posted January 17, 2017 Share Posted January 17, 2017 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; } } }; Link to comment Share on other sites More sharing options...
phreaknation Posted January 17, 2017 Share Posted January 17, 2017 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 mrxj88 1 Link to comment Share on other sites More sharing options...
mrxj88 Posted January 17, 2017 Author Share Posted January 17, 2017 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 Link to comment Share on other sites More sharing options...
phreaknation Posted January 17, 2017 Share Posted January 17, 2017 Meant more of the body debug. See the links belowhttp://phaser.io/examples/v2/arcade-physics/body-debughttp://phaser.io/examples/v2/p2-physics/body-debug Link to comment Share on other sites More sharing options...
mrxj88 Posted January 18, 2017 Author Share Posted January 18, 2017 5 hours ago, phreaknation said: Meant more of the body debug. See the links belowhttp://phaser.io/examples/v2/arcade-physics/body-debughttp://phaser.io/examples/v2/p2-physics/body-debug Oh sorry about that. Ok i think i got what you were talking about. I see that it put a box around my player. how would i fix it so the box is tighter onto his body? Link to comment Share on other sites More sharing options...
mrxj88 Posted January 18, 2017 Author Share Posted January 18, 2017 Hey i figured it out now. I just resized the box using Sprite.body.setSize . And made it tighter to the players body. Thanks again for your help! Link to comment Share on other sites More sharing options...
phreaknation Posted January 18, 2017 Share Posted January 18, 2017 Not a problem. You can also reduce it as well Link to comment Share on other sites More sharing options...
Recommended Posts