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

**URL:** <https://community.haxe.org/t/twinspire-an-open-source-framework-for-2d-graphics-in-kha/2917>\
**Category:** Showcase\
**Created:** [February 21, 2021, 10:23pm UTC](https://community.haxe.org/t/twinspire-an-open-source-framework-for-2d-graphics-in-kha/2917 "2021-02-21T22:23:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tienery](https://community.haxe.org/user_avatar/community.haxe.org/tienery/32/964_2.png) [@tienery](https://community.haxe.org/u/tienery)\
**Post date:** [February 21, 2021, 10:23pm UTC](https://community.haxe.org/t/twinspire-an-open-source-framework-for-2d-graphics-in-kha/2917/1 "2021-02-21T22:23:44Z")

</div>

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](https://github.com/twinspire/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.

---

<div class="post-metadata">

**Author:** ![tienery](https://community.haxe.org/user_avatar/community.haxe.org/tienery/32/964_2.png) [@tienery](https://community.haxe.org/u/tienery)\
**Post date:** [February 26, 2021, 8:12pm UTC](https://community.haxe.org/t/twinspire-an-open-source-framework-for-2d-graphics-in-kha/2917/2 "2021-02-26T20:12:32Z")

</div>

I have added some much needed [tutorials](https://github.com/twinspire/Core/wiki) 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!

---

<div class="post-metadata">

**Author:** ![tienery](https://community.haxe.org/user_avatar/community.haxe.org/tienery/32/964_2.png) [@tienery](https://community.haxe.org/u/tienery)\
**Post date:** [June 2, 2022, 6:55pm UTC](https://community.haxe.org/t/twinspire-an-open-source-framework-for-2d-graphics-in-kha/2917/3 "2022-06-02T18:55:12Z")

</div>

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](https://github.com/twinspire/Core/wiki/Using-the-New-Dimensions-API).

## 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.

---

<div class="post-metadata">

**Author:** ![tienery](https://community.haxe.org/user_avatar/community.haxe.org/tienery/32/964_2.png) [@tienery](https://community.haxe.org/u/tienery)\
**Post date:** [June 3, 2022, 5:26pm UTC](https://community.haxe.org/t/twinspire-an-open-source-framework-for-2d-graphics-in-kha/2917/4 "2022-06-03T17:26:55Z")

</div>

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:

 ![image](https://community.haxe.org/uploads/default/original/2X/4/424199397a223fc0bb7f1f6f815d85c0353dd183.png)

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