Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Liquid ( water ) in the bottle


gzai
 Share

Recommended Posts

hello all,

I had a try that source, but I can't fill that water into container object.

I have a bottle and a polygon of bottle inside the bottle,

when I try to this.fluid.filterArea = this.imgBottle , that water group not fill into polygon of bottle. how to fix that ?

and it's that okay to startSystem 2 physics ? pyhsics BOX2D with physics P2JS

Thank you

preload: function () {

		this.load.image('bottle', 'images/bottle.png');
		this.load.physics('bottlePhysics', 'scripts/bottlePhysics.json');
		this.load.image('water', 'images/water.png');

},

create: function () {

        this.game.physics.startSystem(Phaser.Physics.BOX2D);
        this.game.physics.box2d.setBoundsToWorld();
        this.game.physics.box2d.gravity.y = 1000;

        this.imgBottle = this.add.sprite( this.game.world.centerX , this.game.world.centerY - 550, 'bottle');
        this.imgBottle.anchor.set(0.5);
        this.game.physics.box2d.enable( this.imgBottle );
        this.imgBottle.body.clearFixtures();
        this.imgBottle.body.loadPolygon('bottlePhysics', 'bottle', this.imgBottle );

        this.game.physics.startSystem(Phaser.Physics.P2JS);
        this.game.physics.p2.restitution = 0.8;
        this.game.physics.p2.gravity.y = 1000;
        this.fluid = this.game.add.group();

        for (var i = 0; i < 400; i++) {
            this.randomX = this.game.rnd.between(0, this.game.width);
            this.randomY = this.game.rnd.between(0, this.game.height);
            
            this.droplet = this.game.add.sprite(this.randomX, this.randomY, 'water');

            // Enable physics for the droplet
            this.game.physics.p2.enable( this.droplet );
            this.droplet.body.collideWorldBounds = true;

            // Add a force that slows down the droplet over time
            this.droplet.body.damping = 0.3;

            // This makes the collision body smaller so that the droplets can get
            // really up close and goopy
            this.droplet.body.setCircle(this.droplet.width * 0.3);

            // Add the droplet to the fluid group
            this.fluid.add( this.droplet );
        }

        this.fluid.filterArea = this.imgBottle;

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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