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

How drag group with P2 Physics


Jandeilson
 Share

Recommended Posts

Game.Level1 = {    	create: function () {                        this.game.physics.startSystem(Phaser.Physics.P2JS);                //Background        bg = this.game.add.sprite(0, 0, 'bg_game');        bg.animations.add('loop');        bg.animations.play('loop', 5, true);                //Rotate Heart        //rotateHeart = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'rotateHeart');        //rotateHeart.animations.add('loop');        //rotateHeart.animations.play('loop', 5, true);        //rotateHeart.anchor.setTo(0.5, 0.5);                //Enemy Ball 1        enemyBall = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'enemyBall');                enemyBall.animations.add('loop');        enemyBall.animations.play('loop', 5, true);                enemyBall.pivot.x = 150;        enemyBall.pivot.y = 150;	                            //this.game.add.tween(enemyBall.scale).to( { x: 2.5, y: 2.5 }, 5000, Phaser.Easing.Linear.None, true, 0, 5000, true);        this.game.physics.enable(enemyBall, Phaser.Physics.P2JS);        enemyBall.body.angularVelocity = 10;        enemyBall.body.immovable = true;                //Heart P1        hearts1 = this.game.add.group();        hearts1.enableBody = true;        hearts1.physicsBodyType = Phaser.Physics.P2JS;                    for (var i = 0; i < 4; i++) {                heart1 = hearts1.create(i*176+32, 72, 'heart1');        heart1.inputEnabled = true;        heart1.input.enableDrag();        }            },    	update: function() {            },        hearts1Kill: function (enemyBall, hearts1) {        hearts1.kill();    }};

Above you can see my code, I'll be happy to get your help, because I really do not know how to make it work.

Link to comment
Share on other sites

Not sure, but try this:

Add the proper events to the start and end of the drag.

 

When the drag starts, set heart1.body.moves = false.

 

Set it back to true on the drag stop event.

 

 

Anyway, if you are trying to have the sprite physics affected by dragging, like throwing sprites around with your mouse or finger, I'm not sure that's possible. I made something like this with Phaser 1.6 and I had to record pointer history and set physics values according to that.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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