Jump to content

Tweening a group and updating the bodies of its children


ChrisyChris
 Share

Recommended Posts

I have a group that contains a large number of children that are P2 physics objects.

When I tween the group the sprites all move correctly, but their collisions occur in the position they were prior to the tween.

Is there a good way to update the position of the bodies of all the children?

Heres some super simplified code incase it helps:

game.physics.startSystem(Phaser.Physics.P2JS);
const collisionGroup1 = game.physics.p2.createCollisionGroup();
const collisionGroup2 = game.physics.p2.createCollisionGroup();

const targetsGroup = game.add.group(0,0);
const ammoGroup = game.add.group(0,300);


const target1 = targetsGroup.create(0,0, "key");
const target2 = targetsGroup.create(50,0, "key");

game.physics.enable(target1, Phaser.Physics.P2JS);
game.physics.enable(target2, Phaser.Physics.P2JS);
target1.body.setCollisionGroup(collisionGroup1);
target1.body.collides(collisionGroup2);
target2.body.setCollisionGroup(collisionGroup1);
target2.body.collides(collisionGroup2);

const bullet = ammoGroup.create(0,0, "key2");

game.physics.enable(bullet, Phaser.Physics.P2JS);
bullet.body.setCollisionGroup(collisionGroup2);
bullet.body.collides(collisionGroup1);

game.add.tween(targetsGroup.position).to(
 {y: "-100"},
 300,
 Phaser.Easing.Quadratic.Out,
 true
);

 

Any help would be greatly appreciated, cheers

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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