Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm fairly new to game development and melonjs. Please excuse my dumb question :). I want to implement an audio controller as a GUI element for a music based game. How can I draw basic GUI elements like buttons or text inputs on top of the game screen? I found #276 but have no idea how to use the defined TextInput as a GUI_Object or Renderable. Thanks in advance!

You must be logged in to vote

Hi and welcome then !

We have a UI example here that should help you get started with the corresponding source code here.

However for text input, I would really rather use DOM/CSS elements, as this will be way easier to manage different language/keyboard and so on (unless you have very basic needs).

Replies: 3 comments · 4 replies

Comment options

Hi and welcome then !

We have a UI example here that should help you get started with the corresponding source code here.

However for text input, I would really rather use DOM/CSS elements, as this will be way easier to manage different language/keyboard and so on (unless you have very basic needs).

You must be logged in to vote
4 replies
@proohit
Comment options

Thanks for your reply. Is there an example that uses DOM elements and integrates them into the game? I'm wondering if the DOM state will be handled separately from game state?

@parasyte
Comment options

There's a reeeeeally old example in #276 (comment) which does this. You will have to update it to the new version of melonJS, and replace the jQuery stuff. But the basic idea would still be the same, AFAIK.

@obiot
Comment options

Thanks Jay ! Always nice to see you around here :)

for the example, it should be as follow after updating to melonJS 2 (ES6) :

case TextInput extends Renderable {

    constructor(x, y, type, length) {
        this.$input = $('<input type="' + type + '" required>').css({
            "left" : x,
            "top" : y
        });

        switch (type) {
        case "text":
            this.$input
                .attr("maxlength", length)
                .attr("pattern", "[a-zA-Z0-9_\-]+");
            break;
        case "number":
            this.$input.attr("max", length);
            break;
        }

        $(me.video.getParent()).append(this.$input);
    }

    destroy() {
        this.$input.remove();
    }

};
@obiot
Comment options

also covered in the FAQ here :
https://github.com/melonjs/melonJS/wiki/Frequently-Asked-Questions#form_inputs

Answer selected by obiot
Comment options

see this as well :
https://www.html5gamedevs.com/topic/34357-do-you-build-your-uis-in-melonjs-or-dom/#comment-197361

You must be logged in to vote
0 replies
Comment options

and this: https://github.com/goldfire/CanvasInput

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1066 on January 17, 2022 00:37.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.