Jump to content

images don't collide in the rigth place


Recommended Posts


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.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

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

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

9 hours ago, Skeptron said:

Show us the code for the character please. Did you add gravity to 

Here it is:

this.player = this.add.sprite(5,599,"hombre", 0);
        this.player.body.allowGravity =true;
        this.player.animations.add ("running", [2,3,4], 10, true);
        this.player.animations.add("jumping", [1]);
        this.player.customParams ={};
        this.player.body.gravity.y = 1000;


And here i activate physics and set gravity:


this.game.physics.arcade.gravity.y = 2000;

Link to comment
Share on other sites

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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...