Twinspire - an open source framework for 2D graphics in Kha

Twinspire has been around for a while but it hasn’t been worked on much mainly because I’ve spent the last year working with it and making a video game. A lot of the code that I was using in my video game I have refactored out and placed inside the Core module which now contains the following features:

  • Basic Application Handling and automatic event listening
  • Preset Preloaders and the ability to create a custom Preloader
  • Create and manage back buffers
  • Manage resources in groups with the Resource API.
  • Basic Animation utility
  • StaticBuilder if you prefer coding procedural-style (like me).
  • ExtraMath for additional mathematics functions like random, min and max (which gets either the lowest or highest value from an array of values), and others.
  • Dimensions for layout logic before rendering.
  • TextBuffer for more complex handling of text manipulation and rendering.
  • Graphics extensions for kha.graphics2.Graphics to allow the use of twinspire.geom.Dim, including the native ability to render multiline text without additional requirements.

Let me know what you think or if you have any issues working with Twinspire.

4 Likes

I have added some much needed tutorials onto the website if you would like to better understand Twinspire and start using it properly without having to figure most of it out yourself.

Hopefully these tutorials are good enough for both beginners and the more advanced in this community!

I have now added some more useful functionality to Twinspire, so instead of just updating the main post, I think it might be worth discussing new APIs that have been introduced.

Dimensions

The Dimensions class recently added to Twinspire Core is designed to assist in layout and performing logic on dimensions. Often, when working with anything relating to positions and sizes, there are trivial, if not boilerplate, code that needs performing when needing to layout your interface or other items on the screen.

This class attempts to solve trivial matters by providing useful utilities.

You can find a tutorial on this new API here.

Global Events

Event handling in Twinspire has been rethought. Instead of requiring you to manage your own event loop, the Core library handles all event routines for you, and if you ever need to query mouse positions, touch movements, gamepad buttons, etc., you just need to use the GlobalEvents class. Just remember to use GlobalEvents.end() at the end of each frame to prevent unwanted behaviour.

Resource Management

Resource management has been completely revamped.

Eventually, I will be working on using some form of compression tool to allow you to use “packed” resources and reading them as haxe.io.Bytes that can be read by the underlying code for ease of distribution and will be automatically handled by the new ResourceManager so you don’t have to implement extra logic.

Other Information

On a side note, as I work on an editor for a project I’ve been longing to make in an alternative language to C# (you guessed it, it’s Haxe), I will likely be working on a user interface library making extensive use of the above mentioned features. More on this later.

Thank you for reading.

1 Like

Apologies if it seems annoying that I am posting too often, but I thought it may be a good idea to update you all on a very nice feature that is often sought-after in many areas of programming (at least based on my own needs), and that is multiline multi-formatted text:

Twinspire has been updated with this new feature. You can use it by creating a TextBuffer from twinspire.text.TextBuffer.

3 Likes