Replies: 1 comment
-
Interesting concept. We have some similar capabilities with My proposal is to keep the current state machine (which supports changing states, and within the current state: pause-resume and stop-start) and build this new functionality as a "modal stack" feature. Modality can be simulated (sort of) using the pause-resume feature in a state, but it can only ever be one level deep (pause is a boolean). As a stack, the modality can be multiple levels deep, which is important for deeply nested menu interfaces and so on. For example, it's probably enough to just swap the If this flow is made easier with a simple API, then you get the same kind of benefits as described in the article. Every entity in the container needs to support new callbacks, described in the article as The final point to cover is compositing different modal containers, E.g. a pause modal probably still wants to draw the level and entities below the pause menu. All it needs for this is a reference to its "parent" container (the original As for API? I guess we need a new
The callbacks are optional, and they accept an argument which references the container that was pushed/popped. Both functions are asynchronous, because the actual Example: Simple pause menu // Create a pause menu
var container = new me.ObjectContainer();
var renderer = new game.Renderer();
container.addChild(renderer);
container.addChild(new me.ColorLayer("background", "rgba(0, 0, 0, 0.75)", 1));
container.addChild(new me.ImageLayer("menu_bg", 300, 500, "menu_bg", 2));
container.addChild(new game.Button(100, 50, "Options"));
container.addChild(new game.Button(100, 100, "Restart"));
container.addChild(new game.Button(100, 150, "Exit"));
// Start pause menu modal state
renderer.modalParent = me.game.modal.push(container); The hypothetical Example: Load a new sub-level me.game.modal.push(new me.ObjectContainer(), function (container) {
// This callback fires when the new modal state is ready
// `container` is a reference to the pushed ObjectContainer
me.levelDirector.loadLevel("sublevel");
}); Example: Return to previous level with all entity state preserved: me.game.modal.pop(function (container) {
// This callback fires when the previous modal state is ready
// `container` is a reference to the popped ObjectContainer
console.log("Welcome back!");
}); |
Beta Was this translation helpful? Give feedback.
-
The idea is perform non-destructive State swaps, for use in situations like "Inventory Screen" or "Pause Screen" (accessed by "Play Screen" without destroying the same), as the article below:
http://caspervonb.github.io/2014/03/02/javascript-game-development-game-states.html
"When pushing a state, the previous state will be paused and the new state will be initialized, when popping a state the state is disposed and the previous state is resumed.
This will allow us to temporarily push new states on top on top of the stack, without destroying any of the data of the previous states."
Beta Was this translation helpful? Give feedback.
All reactions