scene2d.ui refactoring

In my quest to make the world a slightly better place, there is new wiki article: scene2d
This will get you acquainted with the scene2d basics. It doesn’t touch on the scene2d.ui package at all, since that is quite complex and needs its own wiki page.

Overall most people seemed generally open to improving scene2d. Hopefully this means you won’t be too upset when you update libgdx’s SVN and have errors in your project! The changes so far should not be too bad at all. Only the scene2d.ui package has been touched. It now has a proper API — all fields are private and are exposed as necessary. This unsurprisingly turned out very clean and means less breakage in the future, since implementations are not exposed. Some other minor changes were made to keep things organized and consistent. ComboBox was misnamed and so becomes SelectBox so we don’t have problems when we add an actual combo box later. scene2d.ui is fully javadoc’ed (except for the TextField, Widget, WidgetGroup, and Window (and Table) classes which will be done soon). These are javadocs so don’t expect to find glamorous tutorials, but it should prove helpful. We do realize that the scene2d.ui stuff is complex enough that a detailed wiki page is needed. That should be coming soon… or at least eventually.

A while ago I added a class called Scaling to the utils package. This handles up or down scaling a source rectange to a target rectangle. Turns out I accidentally had the functionality for and Scaling.fill swapped, so if you are using this class and are wondering why all your stuff is scaled incorrectly, it’s because I fixed it.


scene2d, break everyone?

So, scene2d is a bit of a monster API-wise. It makes extensive use of public and protected fields. Converting this to a nice getters and setters would be quite some effort, and would break literally ALL applications that use scene2d. Fixing up your app would be relatively straightforward, and in the end we would have a nicer API. Do you think this is worth everyone’s effort?


edit by Mario: i take full responsibilty for this. Scared off by Dalvik’s then abymisal method call overhead i went with public fields which made things quite a bit cumbersome over the last few months/weeks. I’m all for change, benchmarking it should be part of that though. My prediction: the effect won’t be as severe as anticipated. I think now is the time that we get those things fixed, our nightlies, SVN tags and releases should relieve the pain for you guys a little. Mea culpa and feedback more than welcome!

Sound API additions for libgdx!

It’s taken me quite some time to get to this, but here it is: All new Sound methods! Let’s get to the core of it.

Every time you call Sound#play() you will get a long. This long identifies that instance of the Sound being played back at the moment. You can use this id to manipulate that sound instance while its playing: loop it, change it’s pitch, volume and panning!

And here is the Sound interface for the lazy

Pretty simple eh? I’ll clean up the small inconsistencies in the Javadocs asap when we do our Javadoc sweep next week.

Three things:

  • setPan() takes the volume as well. Why? Cause i can’t get a hold of the volume of a stream (==sound instance) via Android’s SoundPool and keeping a list is tedious and bound to create leaks and GC invocations.
  • There is not Sound#isPlaying(long soundId). Why? Cause SoundPool doesn’t give me that information. There is no good work around for that (e.g. figuring out the sound length in seconds, and meassuring how long the sound’s been played back does not work as we don’t have an idea about latency on Android)
  • If a sound id is no longer valid and you pass it to any of the methods above… nothing will happen 😀
  • I might have mixed up linear and logarithmic gain/volume along the way for panning. If you find a problem let me know. The OpenAL implementation of panning is kinda hackish but is “good enough”(tm)

One more thing while i’m here: i haven’t been to the forums for a week, i’m sorry. Things are crazy at the moment and on top of that Stef came to SF. This means i won’t be back to the forums for another week.

Enjoy (and test)!