18f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggipackage aurelienribon.tweenengine; 28f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi 38f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi/** 48f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * The TweenAccessor interface lets you interpolate any attribute from any 58f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * object. Just implement it as you want and register it to the engine by 68f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * calling {@link Tween#registerAccessor}. 78f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * <p/> 88f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 98f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * <h2>Example</h2> 108f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 118f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * The following code snippet presents an example of implementation for tweening 128f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * a Particle class. This Particle class is supposed to only define a position 138f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * with an "x" and an "y" fields, and their associated getters and setters. 148f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * <p/> 158f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 168f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * <pre> {@code 178f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * public class ParticleAccessor implements TweenAccessor<Particle> { 188f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * public static final int X = 1; 198f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * public static final int Y = 2; 208f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * public static final int XY = 3; 218f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 228f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * public int getValues(Particle target, int tweenType, float[] returnValues) { 238f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * switch (tweenType) { 248f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * case X: returnValues[0] = target.getX(); return 1; 258f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * case Y: returnValues[0] = target.getY(); return 1; 268f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * case XY: 278f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * returnValues[0] = target.getX(); 288f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * returnValues[1] = target.getY(); 298f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * return 2; 308f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * default: assert false; return 0; 318f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * } 328f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * } 338f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 348f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * public void setValues(Particle target, int tweenType, float[] newValues) { 358f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * switch (tweenType) { 368f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * case X: target.setX(newValues[0]); break; 378f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * case Y: target.setY(newValues[1]); break; 388f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * case XY: 398f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * target.setX(newValues[0]); 408f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * target.setY(newValues[1]); 418f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * break; 428f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * default: assert false; break; 438f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * } 448f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * } 458f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * } 468f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * }</pre> 478f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 488f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * Once done, you only need to register this TweenAccessor once to be able to 498f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * use it for every Particle objects in your application: 508f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * <p/> 518f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 528f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * <pre> {@code 538f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * Tween.registerAccessor(Particle.class, new ParticleAccessor()); 548f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * }</pre> 558f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 568f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * And that's all, the Tween Engine can no work with all your particles! 578f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 588f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @author Aurelien Ribon | http://www.aurelienribon.com/ 598f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi */ 608f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggipublic interface TweenAccessor<T> { 618f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi /** 628f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * Gets one or many values from the target object associated to the 638f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * given tween type. It is used by the Tween Engine to determine starting 648f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * values. 658f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 668f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @param target The target object of the tween. 678f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @param tweenType An integer representing the tween type. 688f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @param returnValues An array which should be modified by this method. 698f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @return The count of modified slots from the returnValues array. 708f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi */ 718f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi public int getValues(T target, int tweenType, float[] returnValues); 728f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi 738f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi /** 748f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * This method is called by the Tween Engine each time a running tween 758f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * associated with the current target object has been updated. 768f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * 778f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @param target The target object of the tween. 788f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @param tweenType An integer representing the tween type. 798f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi * @param newValues The new values determined by the Tween Engine. 808f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi */ 818f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi public void setValues(T target, int tweenType, float[] newValues); 828f2ef8f2d70edcfa159195e2efd23f95ff1b5789Jorim Jaggi} 83