TweenAccessor for music.class in LibGDX

自古美人都是妖i 提交于 2019-12-01 17:31:27

问题


I've been wondering: is it possible to use Universal Tween Engine in LibGDX to - for example - change the volume of a song? I wrote my own MusicAccessor with code similar to my SpriteAccessor, which actually works for Sprite.class, but when it comes to music objects - it always gets the same error:

java.lang.RuntimeException: No TweenAccessor was found for the target

The thing is, I DO register my accessor by: Tween.registerAccessor(Music.class,new MusicAccessor()); I'm quite sure it's actually being registered, as System.out.println(Tween.getRegisteredAccessor(Music.class)); prints: the.name.of.my.packages.MusicAccessor@14bb523. Honestly, I'm stuck.

The music file itself is in .mp3 format and I load it by an asset manager.

So, my questions are: why the Tween Engine cannot correctly recognise the class of my music object? Is there a way to make it work or am I stuck with regular timers to change the volume over time? Would changing the format or loading the music file in a different way help?


回答1:


I personally haven't used Tween Engine myself yet, but I think it might be because Music is actually just an interface.

There are several implementations for the different backends and different file formats. For example AndroidMusic, GwtMusic, and three more implementations of OpenALMusic (they are all called Music and are located in the com.badlogic.gdx.backends.openal.mp3/ogg/wav packages). You could either register them all with your accessor, or you can use Tween.cast() which I found in the code, but not in the official JavaDoc of the tween engine. It might be only in the latest version.



来源:https://stackoverflow.com/questions/20978847/tweenaccessor-for-music-class-in-libgdx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!