0
votes

I am having a difficult time implementing the Universal Tween Engine in my android, desktop, and html libgdx projects (Note that this is a problem with libgdx version 1.3.1 that uses gradle). I have followed the instructions on the github wiki by using the fileTree method shown in the link below. https://github.com/libgdx/libgdx/wiki/Universal-Tween-Engine

I managed to set the build path of the CORE and ANDROID projects to include the two tween engine jars. The classes get imported easily but when runnning the DESKTOP project I get the following error:

Exception in thread "LWJGL Application" java.lang.RuntimeException: No TweenAccessor was found for the target at aurelienribon.tweenengine.Tween.build(Tween.java:787) at aurelienribon.tweenengine.Tween.build(Tween.java:79) at aurelienribon.tweenengine.BaseTween.start(BaseTween.java:85) at aurelienribon.tweenengine.TweenManager.add(TweenManager.java:61) at aurelienribon.tweenengine.BaseTween.start(BaseTween.java:98) at com.infinitybit.killtheclouds.Screens.Splash.show(Splash.java:58) at com.badlogic.gdx.Game.setScreen(Game.java:61) at com.infinitybit.killtheclouds.KillTheClouds.create(KillTheClouds.java:14) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

Here is my code

Splash.java

package com.infinitybit.killtheclouds.Screens;

import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.infinitybit.killtheclouds.KillTheClouds;
import com.infinitybit.killtheclouds.TweenStuff.SplashAccessor;

public class Splash implements Screen {

    public static int SCREEN_WIDTH = Gdx.graphics.getWidth();
    public static int SCREEN_HEIGHT = Gdx.graphics.getHeight();

    private KillTheClouds game;

    private SpriteBatch splashpaper;
    private Sprite splashimage;

    private TweenManager tweenManager;

    public Splash(KillTheClouds game) {

        this.game = game;

    }

    @Override
    public void show() {

        // TweenSTUFF
        tweenManager = new TweenManager();
        Tween.registerAccessor(Sprite.class, new SplashAccessor());

        splashpaper = new SpriteBatch();

        Texture splashTexture = new Texture("images/splash/logo.png");
        splashimage = new Sprite(splashTexture);

        // image size
        splashimage.setSize(SCREEN_WIDTH / 1.5f, SCREEN_HEIGHT / 2);
        // center image
        splashimage.setPosition(SCREEN_WIDTH / 2 - splashimage.getWidth() / 2,
                SCREEN_HEIGHT / 2 - splashimage.getHeight() / 2);

        Tween.set(splashTexture, SplashAccessor.ALPHA).target(0)
                .start(tweenManager);

        Tween.to(splashTexture, SplashAccessor.ALPHA, 3).target(1)
                .start(tweenManager);

        Tween.to(splashTexture, SplashAccessor.ALPHA, 2).target(0).delay(2)
                .start(tweenManager);

    }

    @Override
    public void render(float delta) {

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        // update tween
        tweenManager.update(delta);

        splashpaper.begin();

        splashimage.draw(splashpaper);

        splashpaper.end();

    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void hide() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {

    }

}

SplashAccessor.java

package com.infinitybit.killtheclouds.TweenStuff;

import aurelienribon.tweenengine.TweenAccessor;

import com.badlogic.gdx.graphics.g2d.Sprite;


public class SplashAccessor implements TweenAccessor<Sprite> {

    public static final int ALPHA = 0;

    @Override
    public int getValues(Sprite target, int tweenType, float[] returnValues) {

        switch (tweenType) {

        case ALPHA:
            returnValues[0] = target.getColor().a;
        return 1;

        default:
            assert false;
        return -1;

        }

    }

    @Override
    public void setValues(Sprite target, int tweenType, float[] newValues) {

        float defRed = target.getColor().r;
        float defGreen = target.getColor().g;
        float defBlue = target.getColor().b;

        switch(tweenType){

            case ALPHA:
                target.setColor(defRed, defGreen, defBlue, newValues[0]);
            break;

            default:
                assert false;

        }

    }


}
1

1 Answers

2
votes

Your splashTexture isn't the type of Sprite it is Texture!!!

That is your problem. Create splashSprite from splashTexture, and call this:

Tween.to(splashSprite, SplashAccessor.ALPHA, 3).target(1)
            .start(tweenManager);

Hope it helps!