-
Notifications
You must be signed in to change notification settings - Fork 4
Cheat Sheet
List of the methods available on the class
ParticleSystem
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.
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)
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)
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 anInterpolator -
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)
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)
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().
emit(View emitter, int particlesPerSecond)emit(View emitter, int particlesPerSecond, int emittingTime)
emit(int emitterX, int emitterY, int particlesPerSecond)emit(int emitterX, int emitterY, int particlesPerSecond, int emittingTime)
emitWithGravity(View emitter, int gravity, int particlesPerSecond)emitWithGravity(View emitter, int gravity, int particlesPerSecond, int emittingTime)
-
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.