barbara Posted May 24, 2016 Share Posted May 24, 2016 Hi, I'm writing a platform game in phaser, but the limits of the platforms don't seem to be the same as the limits of the image, so my player can keep walking "in the air" even when there's no platform under him. I`ve attached an image, as you can see there's no cloud under the player, but he`s standing on it anyway, he can walk this far untill fall to the platform below. Here is the "preload()" code part : this.load.image("cloud", "assets/cloud.png"); And here the "create()" code part: this.cloudsData =[ {"x":0 , "y":750}, {"x":200 , "y":600}, {"x":0 , "y":450}, {"x":200 , "y":300} ]; this.clouds = this.add.group(); this.clouds.enableBody = true; this.cloudsData.forEach(function(element){ this.clouds.create(element.x, element.y, "cloud"); }, this); this.clouds.setAll("body.immovable", true); this.clouds.setAll("body.allowGravity", false); I've tried changing the image with the same result, i think the code is wrong but i don't know where. Many thanks. Link to comment Share on other sites More sharing options...
shohan4556 Posted May 25, 2016 Share Posted May 25, 2016 your code seems ok I think you need to set cloud anchor point 0.5. like this this.clouds.setAll('anchor.x', 0.5); this.clouds.setAll('anchor.y', 0.5); Link to comment Share on other sites More sharing options...
Skeptron Posted May 25, 2016 Share Posted May 25, 2016 We'll need to see. In particular, show us the code where you apply collisions. Link to comment Share on other sites More sharing options...
barbara Posted May 25, 2016 Author Share Posted May 25, 2016 Hi shohan4556, I tried, but still happens the same... Hi Skeptron, this is the code for the collisions: this.game.physics.arcade.collide(this.player, this.clouds); Link to comment Share on other sites More sharing options...
drhayes Posted May 25, 2016 Share Posted May 25, 2016 Try putting "this.game.debug.body(cloud);" for each cloud in the render method of your state. If you don't have a render method, make one. ( = That'll show you where the physics bodies are in relation to where the textures are and give you a clue about what you need to fix. Link to comment Share on other sites More sharing options...
barbara Posted May 25, 2016 Author Share Posted May 25, 2016 Hi drhayes, Thankyou for you answer, i will keep this tool But i still can't figure out wich is the problem, i attach another image, so you can see it renders in the correct position, but i still can walk "in the air". Link to comment Share on other sites More sharing options...
Skeptron Posted May 25, 2016 Share Posted May 25, 2016 Show us the code for the character please. Did you add gravity to the world? Link to comment Share on other sites More sharing options...
barbara Posted May 26, 2016 Author Share Posted May 26, 2016 9 hours ago, Skeptron said: Show us the code for the character please. Did you add gravity to Here it is: //player this.player = this.add.sprite(5,599,"hombre", 0); this.game.physics.arcade.enable(this.player); this.player.body.allowGravity =true; this.player.animations.add ("running", [2,3,4], 10, true); this.player.animations.add("jumping", [1]); this.game.camera.follow(this.player); this.player.customParams ={}; this.player.body.gravity.y = 1000; And here i activate physics and set gravity: this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 2000; Link to comment Share on other sites More sharing options...
Skeptron Posted May 26, 2016 Share Posted May 26, 2016 Try debugging the character's hitbox as well? Everything seems very fine. I guess we'll need some more code Link to comment Share on other sites More sharing options...
barbara Posted May 26, 2016 Author Share Posted May 26, 2016 9 hours ago, Skeptron said: Try debugging the character's hitbox as well? Everything seems very fine. I guess we'll need some more code it's the character's hitbox!! I didn't try it, cause i was sure it was a problem with the clouds, my fault! the player image sometimes is out of the render zone... i don't know why, i'm going to try some things so i can fix it! many thanks for your time guys! Link to comment Share on other sites More sharing options...
Recommended Posts