plattysoft / Leonids

A Particle System for standard Android UI: http://plattysoft.github.io/Leonids/
Apache License 2.0
2.28k stars 398 forks source link

Extract emitter shape so it no longer depens on a View. #98

Open pserwylo opened 6 years ago

pserwylo commented 6 years ago

Now, the interface just specifies x, y, width and height. This allows for either a Android View object, or alternatively an arbitrary rectangle to be used for emission locations.

It maintains backward compatibility with the current API by overloading each method which accepts a View. The new method accepts an Emitter, and the old method delegates to the new method, by passing in a new ViewEmitter(view) whenever the new method expects an Emitter.

In the future, this could be further refactored to expose even more flexibility. For example, the entire calculation for initial particle locations into the new Emitter interface. That is to say, instead of it being hard coded to use x, y, width, height (and hence a rectangle emission area), we could instead have an interface which exposes a method generateParticleLocation(). Some emitters may choose to use a rect, others could use a circle. Others could do even more interesting things such as from a point, but randomly distributed around the point according to a Gaussian distribution.

Another future refactoring would be to attach the gravity argument to the Emitter itself. That way the ParticleSystem itself doesn't need to care about whether to anchor particles to the top or bottom of a rectangle area. Instead you would configure this on the emitter object before passing it to the particle system.