1 package aurelienribon.tweenengine; 2 3 /** 4 * The TweenAccessor interface lets you interpolate any attribute from any 5 * object. Just implement it as you want and register it to the engine by 6 * calling {@link Tween#registerAccessor}. 7 * <p/> 8 * 9 * <h2>Example</h2> 10 * 11 * The following code snippet presents an example of implementation for tweening 12 * a Particle class. This Particle class is supposed to only define a position 13 * with an "x" and an "y" fields, and their associated getters and setters. 14 * <p/> 15 * 16 * <pre> {@code 17 * public class ParticleAccessor implements TweenAccessor<Particle> { 18 * public static final int X = 1; 19 * public static final int Y = 2; 20 * public static final int XY = 3; 21 * 22 * public int getValues(Particle target, int tweenType, float[] returnValues) { 23 * switch (tweenType) { 24 * case X: returnValues[0] = target.getX(); return 1; 25 * case Y: returnValues[0] = target.getY(); return 1; 26 * case XY: 27 * returnValues[0] = target.getX(); 28 * returnValues[1] = target.getY(); 29 * return 2; 30 * default: assert false; return 0; 31 * } 32 * } 33 * 34 * public void setValues(Particle target, int tweenType, float[] newValues) { 35 * switch (tweenType) { 36 * case X: target.setX(newValues[0]); break; 37 * case Y: target.setY(newValues[1]); break; 38 * case XY: 39 * target.setX(newValues[0]); 40 * target.setY(newValues[1]); 41 * break; 42 * default: assert false; break; 43 * } 44 * } 45 * } 46 * }</pre> 47 * 48 * Once done, you only need to register this TweenAccessor once to be able to 49 * use it for every Particle objects in your application: 50 * <p/> 51 * 52 * <pre> {@code 53 * Tween.registerAccessor(Particle.class, new ParticleAccessor()); 54 * }</pre> 55 * 56 * And that's all, the Tween Engine can no work with all your particles! 57 * 58 * @author Aurelien Ribon | http://www.aurelienribon.com/ 59 */ 60 public interface TweenAccessor<T> { 61 /** 62 * Gets one or many values from the target object associated to the 63 * given tween type. It is used by the Tween Engine to determine starting 64 * values. 65 * 66 * @param target The target object of the tween. 67 * @param tweenType An integer representing the tween type. 68 * @param returnValues An array which should be modified by this method. 69 * @return The count of modified slots from the returnValues array. 70 */ getValues(T target, int tweenType, float[] returnValues)71 public int getValues(T target, int tweenType, float[] returnValues); 72 73 /** 74 * This method is called by the Tween Engine each time a running tween 75 * associated with the current target object has been updated. 76 * 77 * @param target The target object of the tween. 78 * @param tweenType An integer representing the tween type. 79 * @param newValues The new values determined by the Tween Engine. 80 */ setValues(T target, int tweenType, float[] newValues)81 public void setValues(T target, int tweenType, float[] newValues); 82 } 83