Leonids


Source link: https://github.com/plattysoft/Leonids

Changes in this fork:

  • Spelling fixes
  • Added static method to set FPS
  • Fixed some angle math

Leonids

Leonids is a particle system library that works with the standard Android UI.

The library is extremely lightweight, LeonidsLib.jar is just 81Kb.

You can download Leonids Demo from Google Play to check out what can be done with it.

Setup

Leonids is available in jcenter as well as a jar file to fit both Android Studio and Eclipse.

Android Studio / gradle

Add the following dependency to the build.gradle of your project

dependencies {

  compile 'com.plattysoft.leonids:LeonidsLib:1.3.2' 
}
 

Note: If you get an error, you may need to update the jcenter repository to:

repositories {

  jcenter{

url "http://jcenter.bintray.com/"
  
}
 
}
 

Eclipse / jar file

Just put LeonidsLib.jar into the libs folder of your app.

Why this library?

Particle systems are often used in games for a wide range of purposes: Explosions, fire, smoke, etc. This effects can also be used on normal apps to add an element of "juiciness" or Playful Design.

Precisely because its main use is games, all engines have support for particle systems, but there is no such thing for standard Android UI.

This means that if you are building an Android app and you want a particle system, you have to include a graphics engine and use OpenGL -which is quite an overkill- or you have to implement it yourself.

Leonids is made to fill this gap, bringing particle sytems to developers that use the standard Android UI.

Basic usage

Creating and firing a one-shot particle system is very easy, just 3 lines of code.

new ParticleSystem(this, numParticles, drawableResId, timeToLive) .setSpeedRange(0.2f, 0.5f) .oneShot(anchorView, numParticles);

Note that the ParticleSystem checks the position of the anchor view when oneShot (or emit) is called, so it requires the views to be measured. This means that ParticleSystem won't work properly if you call oneShot or emit during onCreate. For more information check the comments on issue #22.

When you create the particle system, you tell how many particles will it use as a maximum, the resourceId of the drawable you want to use for the particles and for how long the particles will live.

Then you configure the particle system. In this case we specify that the particles will have a speed between 0.2 and 0.5 pixels per milisecond (support for dips will be included in the future). Since we did not provide an angle range, it will be considered as "any angle".

Finally, we call oneShot, passing the view from which the particles will be launched and saying how many particles we want to be shot.

Emitters

You can configure emitters, which have a constant ratio of particles being emited per second. This is the code for the Confeti example:

new ParticleSystem(this, 80, R.drawable.confeti2, 10000) .setSpeedModuleAndAngleRange(0f, 0.3f, 180, 180) .setRotationSpeed(144) .setAcceleration(0.00005f, 90) .emit(findViewById(R.id.emiter_top_right), 8);
  new ParticleSystem(this, 80, R.drawable.confeti3, 10000) .setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0) .setRotationSpeed(144) .setAcceleration(0.00005f, 90) .emit(findViewById(R.id.emiter_top_left), 8);

It uses an initializer for the Speed as module and angle ranges, a fixed speed rotaion and extenal acceleration.

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.

Supported drawables are: BitmapDrawable and AnimationDrawable.

  • ParticleSystem(Activity a, int maxParticles, int drawableRedId, 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 recieve 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 drawableRedId, 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)

Configuration

Available methods on the Particle system 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 endMilis)
  • ScaleModifier (float initialValue, float finalValue, long startMilis, long endMilis, Interpolator interpolator)

One shot

Make one shot using from the anchor view using the number of particles specified, an interpolator is optional

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

Emitters

Emits the number of particles per second from the emitter. If emittingTime is set, the emitter stops after that time, otherwise it is continuous.

####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 emitingTime)

####Emit with Gravity

  • emitWithGravity (View emiter, int gravity, int particlesPerSecond)
  • emitWithGravity (View emiter, int gravity, int particlesPerSecond, int emitingTime)

####Update, stop, and cancel

  • updateEmitPoint (int emitterX, int emitterY) Updates dynamically the point of emission.
  • updateEmitPoint (View emiter, int gravity) Updates dynamically 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 cancles the active ones.

Other details

Leonids requires minSDK 11 because it uses ValueAnimators. It should be very easy, however to use nineoldandroids and make it work on Gingerbread.

The library is Free Software, you can use it, extended with no requirement to open source your changes. You can also make paid apps using it.

Each Particle System only uses one image for the particles. If you want different particles to be emitted, you need to create a Particle System for each one of them.

Resources

A json-api-mock framework for Android.

CodeView helps to show code content with syntax highlighting in native way.

Freeline is a fast build and deployment tool for Android. Caching reusable class files and resource indices, it enables incrementally building Android apps, and optionally deploying the update to your device with hot swap.

A Subclass of ImageView that 'morphs' into a circle shape and can rotates. Useful to be used as album cover in Music apps.

A multi level menu view (like WeChat subscription Accounts) library for Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes