akanarika Posted September 19, 2014 Share Posted September 19, 2014 I want the player and the map layer collide,it should be like this:sometimes it goes well,but sometimes it appears like this: yet I know maybe it's cause by the high gravity(8000), but I have to keep it high because when it jumps, it falls too slowly. However, I don't understand why they won't collide since I coded:this.game.physics.arcade.collide(this.player, this.layer);Here are my source code:Game.Play.prototype = { create: function () { this.game.physics.startSystem(Phaser.Physics.ARCADE); this.faceLeft = true; for(var i=0; i<28; i++){ for(var j=0; j<12; j++){ this.game.add.sprite(60*i, 60*j, 'wall');} } this.map = this.game.add.tilemap('level_1',600,600); this.map.addTilesetImage('collection_1'); // Preloaded tileset this.map.addTilesetImage('player'); // Preloaded tileset this.layer = this.map.createLayer(0); this.layer.resizeWorld(); this.map.setCollisionBetween(0,100,true); this.player = this.game.add.sprite(60*19, 60*10-90, 'player', 18); this.movePlat = this.game.add.sprite(60*13, 60*4, 'movePlat', 2) this.stopLAnim = this.player.animations.add('stopL', [0,1,2,3,4,5], 20, true); this.stopRAnim = this.player.animations.add('stopR', [6,7,8,9,10,11], 20, true); this.moveLAnim = this.player.animations.add('left', [12,13,14], 20, true); this.moveRAnim = this.player.animations.add('right', [15,16,17], 20, true); this.game.physics.enable( [this.player, this.layer, this.movePlat], Phaser.Physics.ARCADE); this.player.body.collideWorldBounds = true; this.player.body.gravity.y = 9000; this.cursor = this.game.input.keyboard.createCursorKeys(); this.game.camera.follow(this.player); this.movePlat.body.immovable = true; //movePlat tween this.tween = this.game.add.tween(this.movePlat).to({ x: 60*17 }, 2000, Phaser.Easing.Linear.None) .to({ x:60*13 }, 2000, Phaser.Easing.Linear.None) .loop() .start(); }, update: function() { this.game.physics.arcade.collide(this.player, this.layer); this.game.physics.arcade.collide(this.player, this.movePlat); this.player.body.velocity.set(0); if (this.cursor.left.isDown) { this.player.body.velocity.x = -300; this.player.play('left'); this.faceLeft = true; } else if (this.cursor.right.isDown) { this.player.body.velocity.x = 300; this.player.play('right'); this.faceLeft = false; } else { if(this.faceLeft) this.player.animations.play('stopL'); else this.player.animations.play('stopR'); } if (this.cursor.up.isDown && this.player.body.blocked.down){ this.player.body.velocity.y = -2000; } if (this.cursor.up.isDown && this.player.body.blocked.down) { this.player.body.velocity.y = -600; //if (sound) this.jump_s.play(); this.playerJumpCount = 1; } else if (this.cursor.up.isDown && this.playerJumpCount < 18 && this.playerJumpCount != 0) { this.playerJumpCount += 1; this.player.body.velocity.y = -650; } else this.playerJumpCount = 0; //if(this.player.body.blocked.down) this.player.body.gravity.y = 100; //else {this.player.body.gravity.y = 6000;} },};Please help me! Thank you!!! Link to comment Share on other sites More sharing options...
lewster32 Posted September 19, 2014 Share Posted September 19, 2014 Gravity this high will cause these problems - I suspect your game is running very slowly (low fps) which affects the physics system quite badly. I'd probably try and work out how to optimise the game at this point - turn off the background, collisions with anything except the player and tilemap etc, then turn things on one at a time to find out what's causing the low fps. Link to comment Share on other sites More sharing options...
Dumtard Posted September 19, 2014 Share Posted September 19, 2014 Increasing the tile bias may help as well. Link to comment Share on other sites More sharing options...
akanarika Posted September 19, 2014 Author Share Posted September 19, 2014 Thank you for answering it.I turned off the background and stopped any animation,but it didn't help, I lowered the gravity to 900, it still fell slowly. > < Link to comment Share on other sites More sharing options...
lewster32 Posted September 19, 2014 Share Posted September 19, 2014 Can you add this to your code (on the second from last line between }, and }; will be perfect) and tell us what sort of fps you're getting please?render: function() { this.game.time.advancedTiming = true; this.game.debug.text(this.game.time.fps || '--', 2, 14, "#ffffff");} Link to comment Share on other sites More sharing options...
akanarika Posted September 19, 2014 Author Share Posted September 19, 2014 Can you add this to your code (on the second from last line between }, and }; will be perfect) and tell us what sort of fps you're getting please?render: function() { this.game.time.advancedTiming = true; this.game.debug.text(this.game.time.fps || '--', 2, 14, "#ffffff");} Thanks, I did that and the output was 60.I'm a newbie so I don't know what it means,,, Link to comment Share on other sites More sharing options...
lewster32 Posted September 19, 2014 Share Posted September 19, 2014 This is very weird, 60 is what you should be getting so that's fine. I can't understand why the gravity is making your object fall so slowly at all... A value of around 500-1000 should be fine for pretty much all cases. 9000 is way too high and at those kinds of velocities you're going to start getting issues with objects going so fast that they go through other objects. Perhaps you can upload your game for us so we can see it running? Link to comment Share on other sites More sharing options...
akanarika Posted September 20, 2014 Author Share Posted September 20, 2014 This is very weird, 60 is what you should be getting so that's fine. I can't understand why the gravity is making your object fall so slowly at all... A value of around 500-1000 should be fine for pretty much all cases. 9000 is way too high and at those kinds of velocities you're going to start getting issues with objects going so fast that they go through other objects. Perhaps you can upload your game for us so we can see it running?https://github.com/akanarika/thisWay //Here is the code, thanks Link to comment Share on other sites More sharing options...
akanarika Posted September 23, 2014 Author Share Posted September 23, 2014 I've found the wrong code line:this.player.body.velocity.set(0);forgot an 'x' !!So stupid...Thanks everyone.. Link to comment Share on other sites More sharing options...
lewster32 Posted September 23, 2014 Share Posted September 23, 2014 Just so you know, velocity is a Phaser.Point object, so you only need to use set/setTo on the object itself - you can change the individual x or y properties just by assigning them:this.player.body.velocity.x = 0; Link to comment Share on other sites More sharing options...
Recommended Posts