1

I am following the tutorial below to add confetti.

final KonfettiView konfettiView = (KonfettiView)findViewById(viewKonfetti);
            konfettiView.build()
                    .addColors(Color.RED, Color.GREEN)                
                    .setSpeed(1f, 5f)
                    .setFadeOutEnabled(true)
                    .setTimeToLive(2000L)
                    .addShapes(Shape.RECT, Shape.CIRCLE)            
                    .setPosition(0f, -359f, -359f, 0f)
                    .stream(200, 5000L);

I want the confetti to appear from top right corner instead of top left. What values should I put in the setPosition method? How does this method work?

I am following this https://github.com/DanielMartinus/Konfetti but there is not much information about the methods and their parameters.

mcfred
  • 1,183
  • 2
  • 29
  • 68
  • Okay so if you will look in `confetti.kt` file; there is the information of location and editing that in your desired way might help you?Have a look at it –  Sep 02 '17 at 18:19

1 Answers1

2

Here is the code on editing which yields you with the desired output:

fun setPosition(x: Float, y: Float): ParticleSystem {
    location.setX(x)
    location.setY(y)
    return this
}

/**
 * Set position range to emit particles from
 * A random position on the x-axis between [minX] and [maxX] and y-axis between [minY] and [maxY]
 * will be picked for each confetti.
 * @param [maxX] leave this null to only emit from [minX]
 * @param [maxY] leave this null to only emit from [minY]
 */
fun setPosition(minX: Float, maxX: Float? = null, minY: Float, maxY: Float? = null): ParticleSystem {
    location.betweenX(maxX, maxX)
    location.betweenY(minY, maxY)
    return this
}

Refer this answer to assemble/adjust the orientation and co-ordinates accordingly.

Also; if you want to put just the co-ordinates; there is a class MotionEvent which has getX() and getY() methods which return the coordinates relative to the view, as you have discovered.

Hope it helps....