bilginhalil Posted September 24, 2015 Share Posted September 24, 2015 Here is my preload function function preload() { game.load.atlas('soldier1', 'assets/spritesheets/soldier4_full.png', 'assets/spritesheets/soldier4_full.json', Phaser.Loader.TEXTURE_ATLAS_JSON_HASH); game.load.image('desert', 'assets/images/desert.png'); game.load.image('desert_ledge', 'assets/images/desert_ledge.png');} And this is createfunction create() { game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.sprite(0, 0, 'desert'); // The platforms group contains the ground and the 2 ledges we can jump on platforms = game.add.group(); platforms.enableBody = true; ledges = [ [0.5, 0.6, 70, 499], [0.5, 0.6, 330, 499], [0.5, 0.6, 600, 499], [0.8, 0.6, 290, 274], [0.5, 0.6, 150, 389], [0.5, 0.6, 500, 389], [0.5, 0.6, 500, 163], [0.5, 0.6, 150, 163], ]; ledges.forEach(function(info){ var ledge = platforms.create(info[2], info[3], 'desert_ledge'); ledge.body.immovable = true; ledge.scale.setTo(info[0], info[1]); }); player = game.add.sprite(50, 150, 'soldier1'); player.anchor.setTo(.5, .5); player.enableBody = true; game.physics.arcade.enable(player); // Player physics properties. Give the little guy a slight bounce. player.body.bounce.y = 0.2; player.body.collideWorldBounds = false; //player.body.setSize(player.body.width*0.7, player.body.height); player.frameName = 'Idle__000.png'; setAnimations(); player.animations.play('walk'); player.body.gravity.y = 700; cursors = game.input.keyboard.createCursorKeys();}Finally here is updatefunction update() { game.physics.arcade.collide(player, platforms, null, function(player, ledge){ if(cursors.down.isDown) { console.log('down'); return false; } if(player.body.velocity.y < 0) return false; return true; }, this); // Reset the players velocity (movement) player.body.velocity.x = 0; if (cursors.left.isDown) { // Move to the left player.body.velocity.x = -150; if(player.scale.x > 0) { player.scale.x *= -1; } if(player.body.touching.down) player.animations.play('walk'); } else if (cursors.right.isDown) { if(player.scale.x < 0) { player.scale.x *= -1; } // Move to the right player.body.velocity.x = 150; if(player.body.touching.down) player.animations.play('walk'); } else { if(player.body.touching.down) player.animations.play('idle'); } if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = -420; player.animations.play('jump'); }}Now When I start the game there is a space between player and ledge which i don't want to exist If i change spritesheet to another atlas space reduces I think this is not about atlas files because when i debug sprites it seems that character doesn't have any padding. So how can i get rid of this problem ? Where am i missing ? Thanks in advance. Link to comment Share on other sites More sharing options...
bilginhalil Posted September 24, 2015 Author Share Posted September 24, 2015 Is there anyone who has an idea about it? Link to comment Share on other sites More sharing options...
drhayes Posted September 24, 2015 Share Posted September 24, 2015 It doesn't look like you're setting the body.width or body.height anywhere. I don't know that that's the problem? And, for platformers, I find setting an anchor of (0.5, 1) to be more helpful -- that way the sprite's position is on the platform. Link to comment Share on other sites More sharing options...
bilginhalil Posted September 24, 2015 Author Share Posted September 24, 2015 Setting anchor to (0.5, 1) amazingly solved the problem. Thanks. )) Should i set the body width or height of a player or ledges ? Is it neccessary? Link to comment Share on other sites More sharing options...
Recommended Posts