Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HTML text outside of the game canvas #2063

Open
jedeen opened this issue Oct 20, 2021 · 4 comments
Open

Add support for HTML text outside of the game canvas #2063

jedeen opened this issue Oct 20, 2021 · 4 comments
Labels
feature Label applied to new feature requests proposal Applied to issues that are a proposal for an implementation stale This issue or PR has not had any activity recently

Comments

@jedeen
Copy link
Member

jedeen commented Oct 20, 2021

Context

It would be very helpful (for development, and accessibility) to be able to synchronize DOM-based text with the game canvas. This could be used for dialogue, subtitles, and more.

Proposal

Add the ability to render HTML-based text alongside the canvas.

@jedeen jedeen added feature Label applied to new feature requests proposal Applied to issues that are a proposal for an implementation labels Oct 20, 2021
@github-actions
Copy link

This issue hasn't had any recent activity lately and is being marked as stale automatically.

@github-actions github-actions bot added the stale This issue or PR has not had any activity recently label Dec 20, 2021
@ufukbakan
Copy link

Why you don't just query select your html element then set its inner html?

Do you need to reflect same text both in excalibur canvas and in HTML DOM? If yes, then

You already can do this, all you need to sync your html elements inner text with your canvas text.
You can do that by implementing your own label class:

import { ActorArgs, Engine, Label, LabelOptions } from "excalibur";

export default class SyncedLabel extends Label{

    target: HTMLElement;

    constructor(options: LabelOptions & ActorArgs, target: HTMLElement){
        super(options);
        this.target = target;
    }

    _postupdate(engine: Engine, delta: number): void {
        super._postupdate(engine, delta);
        this.target.innerHTML = this.text;
    }
}

then create your synced label:

    const mySyncedLabel = new SyncedLabel({
        text: "Hello world",
        pos: new Vector(game.halfDrawWidth, game.halfDrawHeight),
        anchor: new Vector(0.5, 0.5),
        font: new Font({
            family: "Calibri",
            size: 24,
            color: Color.White
        })
    }, document.querySelector("#sync-text")!)

    game.add(mySyncedLabel);
    setTimeout(() => {     mySyncedLabel.text = "I'm updated by excalibur!" }, 1000);

@github-actions github-actions bot removed the stale This issue or PR has not had any activity recently label Jun 28, 2023
@eonarheim
Copy link
Member

@ufukbakan Excellent, that's a good way to do it.

I'd support a PR to the UI section of the docs for HTML https://github.com/excaliburjs/excaliburjs.github.io/blob/site/docs/12-ui.mdx#L60!

@github-actions
Copy link

This issue hasn't had any recent activity lately and is being marked as stale automatically.

@github-actions github-actions bot added the stale This issue or PR has not had any activity recently label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Label applied to new feature requests proposal Applied to issues that are a proposal for an implementation stale This issue or PR has not had any activity recently
Projects
Development

Successfully merging a pull request may close this issue.

3 participants