Rygal reaches 1.2 soon!

Soon I’ll have everything added that was planned for Rygal 1.2, and I’m going to use this post as an opportunity to share more detailed information about the new features.

Recursive Scene Transitions

First of all, it resolves a little bug that is caused by recursive scene transitions. Currently, as soon as you called useScene() to change to a different scene, the Game-class will call unload() on the current scene as well as load() on the upcoming scene. However, this previously caused an issue if you called useScene() in one of the just mentioned (load, unload) methods of your scenes, resulting in an infinite recursion. This then lead to a crash of the game, making it a serious problem. With 1.2, this will be fixed by delaying the scene transition after useScene() to the beginning of the next frame. This also makes it possible to transition to a different scene in your unload()-method, which might come in quite handy in a few cases.

Properties

Furthermore, 1.2 fixes something that has been bothering me since the beginning of Rygal's development and always was too lazy to fix: Read-only variables. Previously, you were even able to programmatically change for example the mousePressed state, just because the corresponding variable was public and not marked as read-only. I now got around to making all these variables read-only properties, which - aside from preventing unwanted behavior - also allows me to redirect variable values to a different variable. For instance, the class Sprite included the attributes width and height. Those two always had to be updated as soon as the texture was changed, but with properties I can now make width and height both access the current texture’s metrics, thus always carrying an up-to-date value.

Multi-touch Support

Besides those enhancements 1.2 also introduces a few new features, whereas one of them is Touch-support. In this case my fellow Kasoki was able to help me out, as I only have an iPhone without a Macbook to develop on, thus requiring someone else to do the work for me. He managed to implement Touch-support and I’m glad that you can now take advantage of Multitouch in your Rygal-driven games.

Rygal UI

I on the other hand was busy developing some other features. One of those being basic UI elements. Previously, displaying text in your game was not that trivial, you had to decide between the easy way of drawing text directly using screen.drawString() in the draw()-method of your scene with the trade-off of low performance, or putting a little more effort into it to make it more performant and caching the text in a texture – with the additional overhead of having to update the texture on every change.

This ridiculously complex way for something seemingly simple is history now, because with 1.2 comes the ingenius class Label, which makes sure to get the best performance, but abstracts all the low-level stuff away to give you an easy-to-use class with simple properties. In this case, it either uses a native TextField for embedded fonts, or the caching method described earlier for bitmap fonts. I’m really proud of this class as it makes it fairly easy to display any textual information in your game and saves you a lot of time in the process.

However, Label is not the only UI element that has been implemented now: There’s now a button class with click events, internally taking advantage of the Label to maintain good performance of course.

Input Abstraction

There are only two things left to do for 1.2, one of them being the last UI element called a TextField, which can be used for text input, as well as an input abstraction layer, which sounds more complicated than it actually is. It’s essentially a class where you can define abstract controls and bind physical inputs to them. I guess it’s easier with a code example:

var c:Controller = new Controller(game);  
c.createInput("MoveRight");  
c.bindKey("MoveRight", Keys.D);  
c.bindKey("MoveRight", Keys.RIGHT);  
if (c.queryInput("MoveRight")) {  
  // Either D or the right arrow is pressed
}

As you can see, you have a controller where you define the control “MoveRight”. Inside your game logic you may only want to ask whether MoveRight is active, and you don't care about which key was pressed or anything like that, it’s something you can do prior to the ingame logic. So, you only have to say “I want to bind this key to MoveRight”, and the controller will do all the work for you. It also allows you to bind multiple keys to the same input. Also planned for the future is for example pointing inputs for mouse and touch devices, or directional input that you can bind keys like WASD or a gamepad thumbstick to. Also planned is the ability to bind a controller to a storage, thus automatically saving the bound keys. That would make it especially easy to have configurable keys that stay persistent. I already had to do that without this Controller class and it was a pain in the ass.

Dragongirl

Apart from engine features, I finally took the time to create a logo for Rygal. Kasoki mentioned that Ryu is the japanese dragon and gal is an urban expression for girl, thus we came up with the idea of Dragongirl, even though the term Rygal was originally derived from Ryntilicious Game Library. You can check out the logo on the official website.