我很难在我的android,desktop和html libgdx项目中实现通用Tween引擎(请注意,这是使用gradle的libgdx版本1.3.1的问题)。 我已经使用下面链接中显示的fileTree方法按照github wiki上的说明进行操作。 https://github.com/libgdx/libgdx/wiki/Universal-Tween-Engine
我设法将CORE和ANDROID项目的构建路径设置为包含两个补间引擎jar。这些类很容易导入,但是当运行DESKTOP项目时,我收到以下错误:
线程“LWJGL Application”中的异常java.lang.RuntimeException:找不到目标的TweenAccessor 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) 在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;
}
}
}
答案 0 :(得分:1)
你的splashTexture不是Sprite的类型,它是纹理!!!
这是你的问题。 从splashTexture创建splashSprite,并调用:
Tween.to(splashSprite, SplashAccessor.ALPHA, 3).target(1)
.start(tweenManager);
希望它有所帮助!