Jandeilson Posted March 29, 2014 Share Posted March 29, 2014 Hi everyone, I'm trying to drag a group of sprites with Physics P2, but not working. Someone can help me? With ARCADE physical drag works, but does not work with P2. Link to comment Share on other sites More sharing options...
Luiz Bills Posted March 29, 2014 Share Posted March 29, 2014 Can show your code? Link to comment Share on other sites More sharing options...
JP91 Posted March 29, 2014 Share Posted March 29, 2014 I'm afraid it's not that simple but not so difficult,I have no code to show but working on it , basically I'm using hitTest(Position,bodies,Precision),toLocalFrame and RevoluteConstraint, that should work. Link to comment Share on other sites More sharing options...
Jandeilson Posted March 31, 2014 Author Share Posted March 31, 2014 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 More sharing options...
Jandeilson Posted April 3, 2014 Author Share Posted April 3, 2014 So ... anyone would know how to do that? Link to comment Share on other sites More sharing options...
mariogarranz Posted April 3, 2014 Share Posted April 3, 2014 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 More sharing options...
Jandeilson Posted April 3, 2014 Author Share Posted April 3, 2014 How do I add proper events to the start and end of the drag? Sorry, but I do not know how to do. :(The only thing I want to do is move sprites "hearts1" group by dragging.Thank you! Link to comment Share on other sites More sharing options...
JP91 Posted April 4, 2014 Share Posted April 4, 2014 hi... this is what I've done, and I hope you find it useful https://googledrive.com/host/0B2Br6oKX-RFNYkJ0YlVtTWJ1UGM/index.html Link to comment Share on other sites More sharing options...
Recommended Posts