plattysoft / Leonids

A Particle System for standard Android UI: http://plattysoft.github.io/Leonids/
Apache License 2.0
2.28k stars 398 forks source link

Particles all appearing on the left side #59

Closed Waro1234 closed 5 years ago

Waro1234 commented 7 years ago

Hey man,

so i was trying to implement your particle system (great job on this) but all the particles on the emitwithgravity all appear on the most left part of the screen. Not at all what was shown in previews.

Greetings

plattysoft commented 7 years ago

You are likely to be seeing the issue #22 when you start the emitter before the views have been measured.

Check out #22 for explanation and solution.

Waro1234 commented 7 years ago

the following code worked for me: `private void makeItRain(){

    rainfall.post(new Runnable() {
        @Override
        public void run() {

            ps = new ParticleSystem(MainActivity.this, 800, rainDrop, 10000);
            ps.setAcceleration(0.00013f, 90)
                    .setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
                    .emitWithGravity(rainfall, Gravity.BOTTOM, 30);
        }
    });

}`

rainfall is the view im calling it from.

Thank you for sending me to the thread.

~Cheers

plattysoft commented 7 years ago

Be aware that the solution may not work in all devices.

You are posting a Runnable to the UI Thread, so it won't be executed on creation, but there is no guarantee that the Runnable will be executed before the views are measured. Since the measurement is done at the very beginning and it is a simple operation, it would work on most cases, but not all of them.