Home » Android » I need particle animation for android with images of our own instead of canvas

I need particle animation for android with images of our own instead of canvas

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am using the library jinatonic_Confetti but there is no possibility of adding images of that particle of our own.

Can anyone help me to get the following Confetti animation that used in IOS has an option to add images but I want to do the same in android IOS library FOR CONFETTI this library can take images for particles?

please help me to get the following animation with my own images.

enter image description here

How to&Answers:

this is late answer but i hope someone will get help from this,
there is cool library that can make things easier for you to animate like particals,
check this library


you can use multipal images in this way,

int[] hearts = {R.drawable.red_heart,R.drawable.pink_heart,R.drawable.blue_heart,R.drawable.green_heart}; 

            for (int heart : hearts) {
               new ParticleSystem(this, 100, heart, 3000)
                  .setAcceleration(0.00013f, 90)
                 .setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
                .setFadeOut(200, new AccelerateInterpolator())
                .emitWithGravity(findViewById(R.id.emiter_top), Gravity.BOTTOM, 30);
            }

Answer:

I’ve successfully implemented custom bitmap confetti using this library

https://github.com/jinatonic/confetti

It is very flexible and besides the direction, speed and rotation you can define your own generator which can return any bitmap you want.

This is an example of a rain effect similar to what you are looking for.

final List<Bitmap> allPossibleConfetti = constructBitmapsForConfetti();
final int numConfetti = allPossibleConfetti.size();
final @ColorRes Integer[] confettiColors = new Integer[] {R.color.redberries, R.color.earthy, R.color.vegetal, R.color.citrus, R.color.blackberries, R.color.tropical};
            final ConfettoGenerator confettoGenerator = random -> {
                final Bitmap bitmap = allPossibleConfetti.get(random.nextInt(numConfetti));
                return new BitmapConfetto(tintBitmap(bitmap, getResources().getColor(confettiColors[random.nextInt(confettiColors.length)])));
            };
                        final ConfettiSource confettiSource = new ConfettiSource(0, -50, flurp.getWidth(), -50);

    new ConfettiManager(FlurpActivity2.this, confettoGenerator, confettiSource, flurp)
                                .setNumInitialCount(0)
                                .setEmissionDuration(ConfettiManager.INFINITE_DURATION)
                                .setEmissionRate(50)
                                .setAccelerationY(10, 5)
                                .setVelocityX(5, 2)
                                .setVelocityY(500, 100)
                                .setInitialRotation(180, 180)
                                .setRotationalAcceleration(360, 180)
                                .setTargetRotationalVelocity(360)
                                .animate();

    private List<Bitmap> constructBitmapsForConfetti() {
        final @DrawableRes Integer[] confettiResources = new Integer[] {R.drawable.confetti_badge, R.drawable.confetti_circle, R.drawable.confetti_ribbon };
        final List<Bitmap> bitmapsForConfetti = new ArrayList<>(confettiResources.length);
        for(@DrawableRes int resId : confettiResources) {
            bitmapsForConfetti.add(BitmapFactory.decodeResource(getResources(), resId));
        }
        return bitmapsForConfetti;
    }

Notice how it will use the basic bitmap confetti and apply random colors to each and every one.

Answer:

Try this :

<com.github.glomadrian.grav.GravView
     android:id="@+id/grav"
     android:layout_centerInParent="true"
     android:layout_width="400dp"
     android:layout_height="400dp"
     app:colorGenerator="com.github.glomadrian.grav.generator.paint.ArrayColorGenerator"
     app:array_colors="@array/red"
     app:pointGenerator="com.github.glomadrian.grav.generator.point.RegularPointGenerator"
     app:regular_cell_size="150"
     app:regular_variance="100"
     app:gravGenerator="com.github.glomadrian.grav.generator.grav.BallGenerator"
     app:ball_size_from_size="3dp"
     app:ball_size_to_size="6dp"
     app:animationGenerators="@array/path"
     app:path_variance_from="-10dp"
     app:path_variance_to="12dp"
     app:path="@string/circle"
     app:path_original_width="@integer/circle_original_width"
     app:path_original_height="@integer/circle_original_height"
     app:path_min_duration="5000"
     app:path_max_duration="6000"
     />

Example here Hope this may help you.