I'm creating this overlays -- such as an inventory UI, as extensions to which melon object? Originally I thought, well easy... me.Container. But as I'm doing most of the interface with HTML markup / CSS added to the DOM... is there really a need to use me.Container, or any other class? Should I simply use me.Object so I can get the "init" as an easy access point to the UI classes?
I don't really think these are "HUD" classes / UI... think RPG when you pull up several layers of menus/UI such as your character, then inventory, spellbook, etc.
(I tried searching here first for info, but I admit I have a hard time discerning what's still valid with the newer versions of melon, etc.)
Thanks for the input ahead of time! Everything I'm already doing WORKS by having HTML templates / CSS and using jQuery to simply clone and display it with the relative data... I'm just wondering if it's best practice with melon! (Thus far, I don't need draw/update functionality, but that could be one reason to eventually use a melon class, though I suspect in that case in one of these generic UI classes, it's a simply matter of creating a class inheriting Renderable or something like that and adding that to the me.game.world container, etc...)
If I do then want to add say, an me.Entity or me.Renderable, to these overlays, they will appear under the HTML DOM element, since these are drawn to the canvas underneath, of course...
I don't suppose there's a way around that, other than creating the entity as another HTML DOM element and separately coding that (i.e., CSS animation, etc)... that 'works', but you lose any of the logic of the class you created for those entities, too...
Any ideas?
This should all sit in an overlay sort of box (div), and with CSS, it's easy to do a little opacity in there to still show part of the game underneath just for aesthetics. But then, like you said, you really can't 'poke a hole' in your div to show canvas items through... and underneath it all in your scene, you still have all those party members in the actual game world, etc...
But now you also want to show them in your GUI... does that make any sense? Or at least, more sense? :)
I might be asking too much out of typical melonjs boundaries... in a traditional game outside of the web, they likely create all these GUI elements as renderables in the canvas/frame, right? And then there's really not this kind of issue at play?
Fun stuff! ;)
When the canvas is the main renderer, we have almost no html UI over top. There are some cases where we do, but they're simple buttons. We never instantiate a new canvas at all, we have one canvas tag that persists in the DOM. We use the gl.flush() method to ensure data gets cleaned up when we're done, but keep it around, as it's more expensive to re-create it. We just resolve the image, load it into our renderer, or an image tag, or it's referenced in css.
I would recommend the same thing here. Use the resources array to look up the image you need, and load it as an image tag inside html.