Hmm, ok let’s try with a timer, test this code in phaser3 sandbox( accessible from any examples with the edit button)
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {
debug: true,
gravity: { y: 0 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('block', 'assets/sprites/block.png');
}
function create ()
{
var group = this.physics.add.group({
collideWorldBounds: true
});
var block1 = group.create(100, 300, 'block').setVelocity(0, 100);
var block2 = group.create(300, 300, 'block').setVelocity(0, -100);
var block3 = group.create(500, 300, 'block').setVelocity(0, 100);
this.time.addEvent({
delay: 2000,
loop: true,
callback: function () {
group.children.entries.forEach(platform => platform.body.velocity.y *= -1);
}
});
this.physics.add.collider(group, group);
}