LibGDX通用补间引擎将补间值设置为零

时间:2014-02-16 17:29:59

标签: java animation libgdx tween

我正在尝试动画从侧面移动的标题 - 一个Vector2保持其预期的最终位置,另一个保持其偏离该位置(偏移量(0,0)表示动画已完成)。我的调试调用显示文本到达最终位置,但是Universal Tween Engine由于某种原因立即将偏移量的值设置为(0,0),而不是补间。下面的代码和调试语句:

初始化TweenManager:

public void show() 
{       
    ...

    //Set up tween manager
    tweenManager = new TweenManager();
    Tween.registerAccessor(Button.class, new ButtonTweenAccessor());
    Tween.registerAccessor(Vector2.class, new Vector2TweenAccessor());
}

开始动画:

public void showLevel(int levelNumber)
{       
    previewTitle = levels[levelNumber].getTitle();
    previewTitlePos.y = GameConstants.getVirtualHeight() - this.TITLE_SPACE;
    previewTitlePos.x = (GameConstants.getVirtualWidth() / 2) - (font.getBounds(previewTitle).width / (2f * GameConstants.getPpuX()));
    titleOffset = new Vector2(GameConstants.getVirtualWidth(), 0);
    Gdx.app.log("Offset before anim starts:", previewTitlePos.toString());

    Tween.to(titleOffset, Vector2TweenAccessor.VALUE, 1)
        .target(.10f, 0.1f)
        .start(tweenManager);

    Gdx.app.log("Offset after tween.to is called:", previewTitlePos.toString());
}

VirtualWidth是游戏内部分辨率中窗口的宽度。我最初将偏移量设置为此值,以将文本“隐藏”一个屏幕长度到屏幕右侧。

然后是渲染方法:

public void render(float delta) 
{       
    spriteBatch.begin();
    if(!previewTitle.isEmpty())
    {
        font.draw(spriteBatch, previewTitle, (previewTitlePos.x + titleOffset.x) * GameConstants.getPpuX(),  (previewTitlePos.y + titleOffset.y) * GameConstants.getPpuY());
        Gdx.app.log("Offset", titleOffset.toString());
    }
    spriteBatch.end();

    tweenManager.update(delta);
}

(我将坐标乘以PpuX和PpuY值以实现分辨率无关 - 我正在处理一个映射到实际窗口分辨率的虚拟分辨率)。

调试输出:

动画开始前的偏移:: [19.0:0.0]

调用tween.to后的偏移量为:: [19.0:0.0]

偏移:[19.0:0.0]

偏移:[0.0:0.0]

偏移:[0.0:0.0]

偏移:[0.0:0.0]

偏移:[0.0:0.0]

偏移:[0.0:0.0]

偏移:[0.0:0.0]

偏移:[0.0:0.0]

等。再过40行左右,直到动画结束。有没有人在我的代码中看到任何会导致此错误的错误?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

好吧,我想出来了 - 事实证明问题出现在我没有提供的一段代码中 - 用于与补间引擎接口的Vector2Accessor类。作为对其他TweenEngine用户的警告,请不要重新初始化放置所访问值的数组。

相关问题