aboutsummaryrefslogtreecommitdiff
path: root/java/api/src/aurelienribon/tweenengine/TweenAccessor.java
blob: 780fb3c2dc4698d69ee5ea77e21dae9d8d4830a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package aurelienribon.tweenengine;

/**
 * The TweenAccessor interface lets you interpolate any attribute from any
 * object. Just implement it as you want and register it to the engine by
 * calling {@link Tween#registerAccessor}.
 * <p/>
 *
 * <h2>Example</h2>
 *
 * The following code snippet presents an example of implementation for tweening
 * a Particle class. This Particle class is supposed to only define a position
 * with an "x" and an "y" fields, and their associated getters and setters.
 * <p/>
 *
 * <pre> {@code
 * public class ParticleAccessor implements TweenAccessor<Particle> {
 *     public static final int X = 1;
 *     public static final int Y = 2;
 *     public static final int XY = 3;
 *
 *     public int getValues(Particle target, int tweenType, float[] returnValues) {
 *         switch (tweenType) {
 *             case X: returnValues[0] = target.getX(); return 1;
 *             case Y: returnValues[0] = target.getY(); return 1;
 *             case XY:
 *                 returnValues[0] = target.getX();
 *                 returnValues[1] = target.getY();
 *                 return 2;
 *             default: assert false; return 0;
 *         }
 *     }
 *
 *     public void setValues(Particle target, int tweenType, float[] newValues) {
 *         switch (tweenType) {
 *             case X: target.setX(newValues[0]); break;
 *             case Y: target.setY(newValues[1]); break;
 *             case XY:
 *                 target.setX(newValues[0]);
 *                 target.setY(newValues[1]);
 *                 break;
 *             default: assert false; break;
 *         }
 *     }
 * }
 * }</pre>
 *
 * Once done, you only need to register this TweenAccessor once to be able to
 * use it for every Particle objects in your application:
 * <p/>
 *
 * <pre> {@code
 * Tween.registerAccessor(Particle.class, new ParticleAccessor());
 * }</pre>
 *
 * And that's all, the Tween Engine can no work with all your particles!
 *
 * @author Aurelien Ribon | http://www.aurelienribon.com/
 */
public interface TweenAccessor<T> {
	/**
	 * Gets one or many values from the target object associated to the
	 * given tween type. It is used by the Tween Engine to determine starting
	 * values.
	 *
	 * @param target The target object of the tween.
	 * @param tweenType An integer representing the tween type.
	 * @param returnValues An array which should be modified by this method.
	 * @return The count of modified slots from the returnValues array.
	 */
	public int getValues(T target, int tweenType, float[] returnValues);

	/**
	 * This method is called by the Tween Engine each time a running tween
	 * associated with the current target object has been updated.
	 *
	 * @param target The target object of the tween.
	 * @param tweenType An integer representing the tween type.
	 * @param newValues The new values determined by the Tween Engine.
	 */
	public void setValues(T target, int tweenType, float[] newValues);
}