SHOW:
|
|
- or go back to the newest paste.
| 1 | package net.dermetfan.someLibgdxTests.tween | |
| 2 | ||
| 3 | import aurelienribon.tweenengine.Tween | |
| 4 | import aurelienribon.tweenengine.TweenAccessor | |
| 5 | import aurelienribon.tweenengine.TweenManager | |
| 6 | import com.badlogic.gdx.graphics.Color | |
| 7 | ||
| 8 | class ColorAccessor implements TweenAccessor<Color> {
| |
| 9 | ||
| 10 | static final int R = 0 | |
| 11 | static final int G = 1 | |
| 12 | static final int B = 2 | |
| 13 | static final int A = 3 | |
| 14 | ||
| 15 | override getValues(Color target, int tweenType, float[] returnValues) {
| |
| 16 | - | returnValues.add(target.r) |
| 16 | + | |
| 17 | case R: {
| |
| 18 | returnValues.set(0, target.r) | |
| 19 | 1 | |
| 20 | - | returnValues.add(target.g) |
| 20 | + | |
| 21 | case G: {
| |
| 22 | returnValues.set(0, target.g) | |
| 23 | 1 | |
| 24 | - | returnValues.add(target.b) |
| 24 | + | |
| 25 | case B: {
| |
| 26 | returnValues.set(0, target.b) | |
| 27 | 1 | |
| 28 | - | returnValues.add(target.a) |
| 28 | + | |
| 29 | case A: {
| |
| 30 | returnValues.set(0, target.a) | |
| 31 | 1 | |
| 32 | } | |
| 33 | default: | |
| 34 | -1 | |
| 35 | } | |
| 36 | } | |
| 37 | ||
| 38 | override setValues(Color target, int tweenType, float[] newValues) {
| |
| 39 | switch (tweenType) {
| |
| 40 | case R: | |
| 41 | target.r = newValues.get(0) | |
| 42 | case G: | |
| 43 | target.g = newValues.get(0) | |
| 44 | case B: | |
| 45 | target.b = newValues.get(0) | |
| 46 | case A: | |
| 47 | target.a = newValues.get(0) | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | def static void main(String[] args) {
| |
| 52 | val manager = new TweenManager | |
| 53 | var color = new Color | |
| 54 | ||
| 55 | Tween.registerAccessor(Color, new ColorAccessor) | |
| 56 | Tween.to(color, R, 2).target(5).start(manager) | |
| 57 | ||
| 58 | for (i : 0 .. 1000) {
| |
| 59 | manager.update(1 / 60f) | |
| 60 | println(color.r) | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | } |