barbara

images don't collide in the rigth place

Recommended Posts

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.

 

imprPant.jpg

Share this post


Link to post
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.

Share this post


Link to post
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".

renderImage.png

Share this post


Link to post
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:

//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;

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.