Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Cheat Sheet

Thomas Orlando edited this page Jun 8, 2020 · 8 revisions

Table of Contents

Available Methods

List of the methods available on the class ParticleSystem

Constructors

All constructors use the activity, the maximum number of particles and the time to live. The difference is in how the image for the particles is specified.

Single-Image Constructors

Supported drawables are: BitmapDrawable and AnimationDrawable

  • ParticleSystem(Activity a, int maxParticles, int drawableResId, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive)

There are also constructors that receive a view ID to use as the parent so you can put the particle system on the background (or between any two views).

  • ParticleSystem(Activity a, int maxParticles, int drawableResId, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive, int parentViewId)

And another constructor that receives a parent ViewGroup and Drawable for use in places where it is not practical to pass a reference to an Activity.

  • ParticleSystem(ViewGroup parentView, int maxParticles, Drawable drawable, long timeToLive)

Version 1.4 Multiple-Image Constructors

With version 1.4 (currently in development), a single particle system can use more than one image.
The new constructors allow a Bitmap[] array to be passed as image parameter (the bitmaps are randomly assigned to particles).

  • ParticleSystem(Activity a, int maxParticles, Bitmap[] bitmaps, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Bitmap[] bitmaps, long timeToLive, int parentViewId)
  • ParticleSystem(ViewGroup parentView, int maxParticles, Bitmap[] bitmaps, long timeToLive)

Configuration

Available methods on the ParticleSystem for configuration are:

  • setSpeedRange(float speedMin, float speedMax) Uses 0-360 as the angle range
  • setSpeedModuleAndAngleRange(float speedMin, float speedMax, int minAngle, int maxAngle)
  • setSpeedByComponentsRange(float speedMinX, float speedMaxX, float speedMinY, float speedMaxY)
  • setInitialRotationRange (int minAngle, int maxAngle)
  • setScaleRange(float minScale, float maxScale)
  • setRotationSpeed(float rotationSpeed)
  • setRotationSpeedRange(float minRotationSpeed, float maxRotationSpeed)
  • setAcceleration(float acceleration, float angle)
  • setFadeOut(long milisecondsBeforeEnd, Interpolator interpolator) Utility method for a simple fade out effect using an Interpolator
  • setFadeOut(long duration) Utility method for a simple fade-out

You can start the particle system "in the future" if you want to have the particles already created and moving using

  • setStartTime(int time)

For more complex modifiers, you can use the method addModifier(ParticleModifier modifier). Available modifiers are:

  • AlphaModifier(int initialValue, int finalValue, long startMilis, long endMilis)
  • AlphaModifier(int initialValue, int finalValue, long startMilis, long endMilis, Interpolator interpolator)
  • ScaleModifier(float initialValue, float finalValue, long startMilis, long endMillis)
  • ScaleModifier(float initialValue, float finalValue, long startMilis, long endMillis, Interpolator interpolator)

One shot

Make one shot from the anchor view using the number of particles specified, with an optional custom Interpolator.

  • oneShot(View anchor, int numParticles)
  • oneShot(View anchor, int numParticles, Interpolator interpolator)

Emitters

Emits the specified number of particles per second from the emitter. If emittingTime is set, the emitter stops after that time, otherwise particles are emitted continuously.
The emitter can be stopped manually by calling stopEmitting() or cancel().

Basic emitters

  • emit(View emitter, int particlesPerSecond)
  • emit(View emitter, int particlesPerSecond, int emittingTime)

Emit based on (x,y) coordinates

  • emit(int emitterX, int emitterY, int particlesPerSecond)
  • emit(int emitterX, int emitterY, int particlesPerSecond, int emittingTime)

Emit with gravity

  • emitWithGravity(View emitter, int gravity, int particlesPerSecond)
  • emitWithGravity(View emitter, int gravity, int particlesPerSecond, int emittingTime)

Update, stop, and cancel

  • updateEmitPoint(int emitterX, int emitterY) Dynamically updates the point of emission.
  • updateEmitPoint(View emitter, int gravity) Dynamically updates the point of emission using gravity.
  • stopEmitting() Stops the emission of new particles, but the active ones are updated.
  • cancel() Stops the emission of new particles and cancels the active ones.