Hi!
I’m new at Phaser, and game development.
I’m creating a card game using Phaser 3 and I have runned into trubble when I need to synchronize the movement of a lot of cards. I tried to use the .on(‘complete’) but realized that I have to wait for .on(‘complete’) for all cards in some way. I can think of a model when I have a counter for each tween started and send an emit signal when the counter has reach it’s goal. But I thinks that maybe there is a Phaser 3 solution to this problem.
My code looks like this:
showAllPointCards() {
for (let key in this.sprites_hash) {
this.sprites_hash[key].setScale(0.5);
}
let lastUpperMatadorTween = [];
let lastLowerMatadorTween = [];
let lastUpperCourtTween = [];
let lastLowerCourtTween = [];
let upper_matadors = this.judge.getUpperHandMatadors();
let x = 0;
upper_matadors.forEach(e => {
let current_sprite = this.sprites_hash[e];
lastUpperMatadorTween.push(this.tweens.add({
targets: current_sprite,
// x: HAND_DIST_FROM_VERTICAL_BORDERS + x * current_sprite.width
// + 20,
x: () => {return HAND_DIST_FROM_VERTICAL_BORDERS + x * current_sprite.width + 20},
y: HAND_DIST_FROM_HORISONTAL_BORDERS,
ease: 'Linear',
duration: SPEED * 5,
angle: 0
}));
x += 1;
this.showFront(e);
});
let lower_matadors = this.judge.getLowerHandMatadors();
x = 0;
lower_matadors.forEach(e => {
let current_sprite = this.sprites_hash[e];
lastLowerMatadorTween.push(this.tweens.add({
targets: current_sprite,
x: HAND_DIST_FROM_VERTICAL_BORDERS + x * current_sprite.width + 20,
y: this.game.renderer.height - HAND_DIST_FROM_HORISONTAL_BORDERS,
ease: 'Linear',
duration: SPEED * 5,
angle: 0
}));
x += 1;
this.showFront(e);
});
let upper_courts = this.judge.getUpperHandCourts();
x = 0;
upper_courts.forEach(e => {
let current_sprite = this.sprites_hash[e];
lastUpperCourtTween.push(this.tweens.add({
targets: current_sprite,
x: HAND_DIST_FROM_VERTICAL_BORDERS + x * current_sprite.width + 20,
y: HAND_DIST_FROM_HORISONTAL_BORDERS + current_sprite.height + 20,
ease: 'Linear',
duration: SPEED * 5,
angle: 0
}));
x += 1;
this.showFront(e);
});
let lower_courts = this.judge.getLowerHandCourts();
x = 0;
lower_courts.forEach(e => {
let current_sprite = this.sprites_hash[e];
lastLowerCourtTween.push(this.tweens.add({
targets: current_sprite,
x: HAND_DIST_FROM_VERTICAL_BORDERS + x * current_sprite.width + 20,
y: this.game.renderer.height - HAND_DIST_FROM_HORISONTAL_BORDERS -
current_sprite.height - 20,
ease: 'Linear',
duration: SPEED * 5,
angle: 0
}));
x += 1;
this.showFront(e);
});
// What to do here?
// lastUpperMatadorTween.forEach(e => {e.on('complete', () => {})});
// lastLowerMatadorTween.forEach(f => {f.on('complete', () => {})});
// lastUpperCourtTween.forEach(g => {g.on('complete', () => {})});
// lastLowerCourtTween.forEach(h => {h.on('complete', () => {})});
// this.newSingleDeal();
}
Anyone that have some advices for me?