Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Phaser 3: Allow Particles to emit with flipped/mirrored image?

I have a particle emitter which emits multiple duplicates of the same image, as usual. However I'd like some of the particles to be flipped, either completely at a random amount, or sort of in the middle, so that particles falling to the left would be flipped and particles falling to the right won't be.

However I couldn't find anything regarding flipping particles without flipping ALL of them. I'd only like some to be flipped. Is this possible in any way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are serveral way's, I think the "fastest" would be just to use the scaleX property of the emiter.

this code flips about 10% of the particles ( 0.9 > Math.random() ), through multiplying it with -1, when it should be flipped.

Example Code:

this.add.particles('sparkle').createEmitter({
    x: 200,
    y: 100,
    scaleX: {
        onEmit: function () { 
            return ( 0.9 > Math.random() ) ? -1 : 1;
        }
    },
    speed: { min: -100, max: 100 },
    quantity: 0.1,
    frequency: 1,
});

But I assume from a earlier question, that you have emitter with a "random scale" property. I that case you woud have to do something like this:

Example Code, for random scaled particles:

gameState.splash = this.add.particles('droplet').createEmitter({
    x: gameState.height/2,
    y: gameState.width/2,
    scale:  { 
        onEmit: function () {
            // create random new scale
            let newRandowmScale = Phaser.Math.FloatBetween(0.05, 0.3);
            return ( 0.9 > Math.random() ) ? -1 * newRandowmScale  : newRandowmScale;
         }
    },
    speed: { min: -100, max: 100 },
    ...
});

UPDATE(SlowerFix): Example Code, for random scaled particles:

What the update does: save the current scale of the scaleX event and use it in the scaleY event. (it is hacky, but should work. I will see if there is a cleaner solution)

gameState.splash = this.add.particles('droplet').createEmitter({
    x: gameState.height/2,
    y: gameState.width/2,
    scaleY:{
        onEmit: function(particle){
            // keep scale value positive
            return Math.abs(particle.scaleX);
        }
    },
    scaleX:{
        onEmit: function(p){
            let scale = Phaser.Math.FloatBetween(.2, .5);
            return Math.random() > .9 ? scale * -1 : scale;
        }
    }, 
    speed: { min: -100, max: 100 },
    ...
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!