Search code examples
androidanimationondrawparticlesparticle-system

I need to make a particle animation but the particles always start from pixel 0,0


This is the animation that I need to make: https://www.dropbox.com/s/xvyj550i43gg6wz/2015-08-24%2013.12.57.mp4?dl=0 I started working on it, using the Leonids library: https://github.com/plattysoft/Leonids Now I made a particleSystem creator, and I set it on my emitter, but the app will always start splashing particles from the 0,0 (top-left) point of the screen. How can I make it emit from my view? This is how I initiate it:

  new ParticleSystem(PSHiscoreAnimationActivity.this, 1000, R.drawable.icn_planning_dot, 10000)
            .setAcceleration(0.00013f, 90)
            .setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
            .setFadeOut(200, new AccelerateInterpolator())
            .emitWithGravity(emitter, Gravity.BOTTOM, 30);

This is my layout:

<View android:id="@+id/emitter"
    android:layout_centerInParent="true"
    android:background="@color/blue"
    android:layout_width="10dp"
    android:layout_height="10dp" />


Solution

  • It seems the problem could be where you are initiating it. See Issue #22 of the github project where someone else has the problem of the particles coming from the top left. If you are calling this from within onStart or onCreate it won't work properly because the views have not been measured yet and they suggest using a ViewTreeObserver as in this Stackoverflow answer