ScavaJripter Posted September 11, 2014 Share Posted September 11, 2014 So my game, ( http://narric.com/underdog_football/ ), has this problem where i go through the tile map when I fall from high spots or if i jump up with high velocity. I have the gravity really high, when i lower it there is no problem, BUT I WANT THE GRAVITY HIGH! I don't think its a problem with the tile map because there is no problem when i lower the gravity and jump velocity.The code below isnt all the code for the game. (I normally have "preload" in another .js file and i got rid of the code for the intro screen and there is a boot file thats not included). I'm new to phaser and coding in general so any help is appreciated.var game = new Phaser.Game(1152,672, Phaser.AUTO, 'game_div');preload: function() { this.load.image('box', 'images/box.png'); // loading the tileset image this.load.tilemap('boxy', 'images/boxy.json', null, Phaser.Tilemap.TILED_JSON); this.load.spritesheet('player', 'images/football_sprite20.png',72,132,20); },create: function() { this.physics.startSystem(Phaser.Physics.ARCADE); map = this.add.tilemap('boxy'); // Preloaded tilemap map.addTilesetImage('box'); // Preloaded tileset layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); map.setCollisionBetween(0, 1); this.player = this.add.sprite(100, 100, 'player'); this.player.anchor.setTo(.5, 1); this.player.animations.add('walking', [0,1,2,3,4,5,6,7], 18, true); this.player.animations.add('sprinting', [12,13,14,15,16,17,18,19], 25, true); this.player.animations.add('jumping', [11], false); this.player.animations.add('idle', [8,9,10,9], 4, true); this.physics.arcade.enableBody(this.player); this.player.body.collideWorldBounds = true; this.player.body.bounce.y = 0.05; this.player.body.gravity.y = 5000; this.player.scale.x = 1; this.player.scale.y = 1; cursors = this.input.keyboard.createCursorKeys(); jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);},update: function() { this.physics.arcade.collide(this.player, layer); this.player.body.velocity.x = 0; //====JUMPING==== jumpButton.onDown.add(jumpAction, this); function jumpAction(){ if (this.player.body.onFloor()) { this.player.body.velocity.y = -1400; this.player.body.gravity.y = 5000; this.player.animations.play('jumping'); if (cursors.down.isDown || sKey.isDown) { this.player.body.velocity.y = -1800; this.player.body.gravity.y = 5500; } } } //====MOVING LEFT==== if (cursors.left.isDown) { this.player.body.velocity.x = -500; this.player.scale.x = -1; this.player.scale.y = 1; if (cursors.down.isDown && this.player.body.onFloor()) { this.player.body.velocity.x = -730; this.player.animations.play('sprinting'); } else if(this.player.body.onFloor()){ this.player.animations.play('walking'); } } //====MOVING RIGHT==== else if (cursors.right.isDown) { this.player.body.velocity.x = 500; this.player.scale.x = 1; this.player.scale.y = 1; if (cursors.down.isDown && this.player.body.onFloor()) { this.player.body.velocity.x = 730; this.player.animations.play('sprinting'); } else if(this.player.body.onFloor()){ this.player.animations.play('walking'); } } //====STANDING IDLE==== else if(this.player.body.onFloor()){ this.player.animations.play('idle'); } }}; Link to comment Share on other sites More sharing options...
Recommended Posts