Replies: 4 comments 2 replies
-
One of my thoughts has always been whether we could actually use JSX for UI with Excalibur. JSX is agnostic of framework, but it provides the familiar XML-like DOM syntax we could then transform into Excalibur logic (like ECS). It's composable, which fits with the general idea in Excalibur of having primitives that you can build into more complex things. That way, we could provide a set of basic, accessible UI building blocks that people can build off of, or even create whole design systems on top of as separate projects. The goals here would be not to necessarily tie Excalibur straight to a DOM UI implementation; but to use JSX as the abstraction so that we can support a flexible renderer system. This would allow you to extend, or other people to extend, so you could build custom renderers. In this way you could do stuff like this: class Menu extends Scene {
public drawUI(engine: Engine) {
return (
<MainMenuList pos={vec(engine.halfDrawWidth, engine.halfDrawHeight)}>
<MainMenuButton to={LevelOneScene} />
<MainMenuButton to={SettingsScene} />
</MainMenuList>
)
}
} This way you could express the UI tree in a familiar way instead of It's only a thought though, I don't know what this really entails 😅 Prior Art |
Beta Was this translation helpful? Give feedback.
-
I think integrating a way to build UIs on top of Excalibur is a great idea. I still don't quite follow the exact problem you're trying to solve though. Is it:
The solutions for each of these sound like 3 different levels of abstraction:
I’m personally leaning to option 1 for many reasons. There are already a lot of ways to write markup, and I worry that requiring people to use a different syntax for writing UIs might increase friction. It's also probably going to take a lot of work to get the DX feeling right. As a web developer, I'd feel right at home building UIs in my template language of choice (either Svelte or Lit). Off the top of my head, there are a couple of ways that we can achieve this:
I haven’t used Nanostores much, but it’s a framework-agnostic way of sharing state. Maybe it could be used to share the state between the canvas and any UIs on top of it. I think this would be a good start because building a suite of accessible components that are battle-tested is hard. In fact, there are a lot of tools that offer headless components, that just deal with the accessible implementation and then let developers style it to their heart’s content. Radix UI, MUI Base, Shoelace. The problem with this approach is that you may be locking users into a specific ecosystem (Radix and MUI are built on React). Shoelace is built on top of Web Components which is supported natively in the browser, so that might be something to consider. Many tools like React Aria have been in development for years, and are dedicated to the cause of building accessible components. I think it would be tricky to try and build something of that scale from scratch. My biggest concern with option 3 is the idea of providing ready-made components that are both specific to video game UI, while being flexible enough to allow developers to build anything they want with it. I haven’t used any other game engines, and so I don’t know how they approach drop-in UIs, so I don’t have as much to say about this. |
Beta Was this translation helpful? Give feedback.
-
@kamranayub This looks wonderful. Nice work. I love composability. |
Beta Was this translation helpful? Give feedback.
-
Another brainstorming thought that came to mind in thinking about using Lit with React. There is lit-react lib which adds a wrapper around a Lit component that wires it into the React lifecycles. |
Beta Was this translation helpful? Give feedback.
-
I'd like to get some thoughts out to start a discussion regarding creating UI components built into Excalibur that meets accessibility as well as web standards.
I haven't thought everything all the way through, just wanting to get the conversation started.
General:
engine.screen.worldToPageCoordinates(...)
though we will need to have resize functionality to move things around.An overlay is not necessarily required as putting HTML elements above the canvas would work. Though I do think it helps manage the UIs as a whole.
Overlay/ Container:
HTML Components:
These examples are me trying to visualize and give us more concrete examples for discussion.
I am not a big fan of the second pattern. It is an older approach. I feel it increases cognitive load for the developer and anyone reading their code because you need to remember the parameter list, or need to break away from what you are doing to look it up. And then there are the nulls that need to be in place when you want to use a parameter later in the list.
We would need to think about how we could implement reactivity for the generic HTML component. Perhaps a generic event listener? It should also allow for variables/placeholders for values?
Maybe even a combined approach with 1 and 2:
Note: In Phaser3, you set a button as interactive and that wires up an EventEmitter.
Beta Was this translation helpful? Give feedback.
All reactions