【问题标题】:Libgdx V1.3.1 Splash Screen Tween Error: Exception in thread "LWJGL Application" java.lang.RuntimeException: No TweenAccessor was found for the targetLibgdx V1.3.1 启动画面补间错误:线程“LWJGL 应用程序”中的异常 java.lang.RuntimeException:没有为目标找到 TweenAccessor
【发布时间】:2025-12-16 04:20:06
【问题描述】:

我很难在我的 android、桌面和 html libgdx 项目中实现通用补间引擎(请注意,这是使用 gradle 的 libgdx 版本 1.3.1 的问题)。 我已按照 github wiki 上的说明使用下面链接中显示的 fileTree 方法。 https://github.com/libgdx/libgdx/wiki/Universal-Tween-Engine

我设法将 CORE 和 ANDROID 项目的构建路径设置为包含两个补间引擎 jar。这些类很容易导入,但是在运行 DESKTOP 项目时出现以下错误:

线程“LWJGL 应用程序”java.lang.RuntimeException 中的异常:未找到目标的 TweenAccessor 在 aurelienribon.tweenengine.Tween.build(Tween.java:787) 在 aurelienribon.tweenengine.Tween.build(Tween.java:79) 在 aurelienribon.tweenengine.BaseTween.start(BaseTween.java:85) 在 aurelienribon.tweenengine.TweenManager.add(TweenManager.java:61) 在 aurelienribon.tweenengine.BaseTween.start(BaseTween.java:98) 在 com.infinitybit.killtheclouds.Screens.Splash.show(Splash.java:58) 在 com.badlogic.gdx.Game.setScreen(Game.java:61) 在 com.infinitybit.killtheclouds.KillTheClouds.create(KillTheClouds.java:14) 在 com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136) 在 com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

这是我的代码

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;

        }

    }


}

【问题讨论】:

    标签: gradle libgdx


    【解决方案1】:

    你的 splashTexture 不是 Sprite 的类型,它是 Texture !!!

    那是你的问题。 从 splashTexture 创建 splashSprite,并调用它:

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

    希望对你有帮助!

    【讨论】:

    • 感谢您的帮助!
    • 很高兴能帮到你。随意接受答案。
    最近更新 更多