Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature add custom emitter #26

Merged

Conversation

DanielMartinus
Copy link
Owner

@DanielMartinus DanielMartinus commented Sep 3, 2017

With this pull request you're able to add your own custom emitter to Konfetti.

Custom Emitter

Extend from the following Emitter class to implement your custom emitter

/**
 * Created by dionsegijn on 9/03/17.
 *
 * An abstract class for creating a custom emitter
 * The only goal of the emitter is to tell when and how many particles to create
 */
abstract class Emitter {

    /**
     * Call this function to tell the RenderSystem to render a particle
     */
    var addConfettiFunc: (() -> Unit)? = null

    /**
     * This function is called on each update when the [RenderSystem] is active
     * Keep this function as light as possible otherwise you'll slow down the render system
     */
    abstract fun createConfetti(deltaTime: Float)

    /**
     * Tell the [RenderSystem] when the emitter is done creating particles
     * @return true if the renderSystem is not longer creating any particles
     *         false if the renderSystem is still busy
     */
    abstract fun isFinished(): Boolean
}

See BurstEmitter or StreamEmitter for examples

To start using your custom Emitter, call the following function in ParticleSystem and supply it with your custom emitter:

/**
 * Add your own custom Emitter. Create your own class and extend from [Emitter]
 * See [BurstEmitter] and [StreamEmitter] as example classes on how to create your own emitter
 * By calling this function the system wil start rendering the confetti according to your custom
 * implementation
 * @param [emitter] Custom implementation of the Emitter class
 */
fun emitter(emitter: Emitter) {
    startRenderSystem(emitter)
}

Calling your custom emitter will look something like this:

viewKonfetti.build()
    .addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
    ... // other properties
    .emitter(CustomEmitter())

@DanielMartinus DanielMartinus merged commit 661eac9 into fix/issue_20_particles_per_second Sep 3, 2017
@DanielMartinus DanielMartinus deleted the feature/add_custom_emitter branch September 3, 2017 18:35
@DanielMartinus DanielMartinus mentioned this pull request Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant