【问题标题】:I need particle animation for android with images of our own instead of canvas我需要带有我们自己的图像而不是画布的 android 粒子动画
【发布时间】:2019-03-23 16:17:50
【问题描述】:

我正在使用库jinatonic_Confetti,但不可能添加我们自己的那个粒子的图像。

谁能帮我获得以下在 IOS 中使用的五彩纸屑动画有一个添加图像的选项,但我想在 android IOS library FOR CONFETTI 中做同样的事情@这个库可以为粒子拍摄图像?

请帮我用我自己的图像制作以下动画。

【问题讨论】:

  • 鉴于这两个项目都是开源的 - 您尝试解决什么问题?
  • 我对粒子动画一无所知,我是新手,但我想这样做,您可以参考任何相关的文档或链接
  • 检查这个animation lib
  • @NileshRathod 我想添加我自己的图片你能帮我怎么做吗

标签: android android-animation


【解决方案1】:

这是迟到的答案,但我希望有人能从中得到帮助, 有一个很酷的库,可以让你更轻松地制作动画,比如partials, check this library


您可以通过这种方式使用多张图片,

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);
            }

【讨论】:

    【解决方案2】:

    我已经使用这个库成功实现了自定义位图五彩纸屑

    https://github.com/jinatonic/confetti

    它非常灵活,除了方向、速度和旋转之外,您还可以定义自己的生成器,它可以返回您想要的任何位图。

    这是一个类似于您正在寻找的雨效果的示例。

    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;
        }
    

    注意它将如何使用基本的位图五彩纸屑并将随机颜色应用于每一个。

    【讨论】:

      【解决方案3】:

      试试这个:

      <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希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-20
        • 1970-01-01
        • 2013-10-03
        • 1970-01-01
        • 2018-11-25
        相关资源
        最近更新 更多