-
Notifications
You must be signed in to change notification settings - Fork 3
Basics 4 (Stack of scenes)
Matheus Pimenta edited this page Mar 29, 2014
·
12 revisions
#Tutorial navigation
- [Previous: Basics 3 (Game components)](Basics 3 (Game components))
- Current: Basics 4 (Stack of scenes)
- [Next: Basics 5 (Rendering)](Basics 5 (Rendering))
#Game
The Game
class provides methods to manipulate the stack of GameScene
.
-
Game.change(GameScene scene)
This method will make the engine pop the scene in the top of the stack and will pushscene
. -
Game.push(GameScene scene)
This method will make the engine pushscene
. -
Game.pop(Object... args)
This method will make the engine pop the scene in the top of the stack and, if there is any scene remaining, will call theGameScene.wakeup(Object... args)
method, passingargs
as argument. -
Game.quit()
This method will make the engine clear the stack, causing the interruption of the main loop.
#Full working code
package mygame.scene;
import org.unbiquitous.uImpala.engine.core.GameComponents;
import org.unbiquitous.uImpala.engine.core.GameScene;
import org.unbiquitous.uImpala.engine.core.Game;
public class MyFirstScene extends GameScene {
private Game game;
public MyFirstScene() {
game = GameComponents.get(Game.class);
}
protected void update() {
if (false) // if user pressed 'enter'
game.change(new MyLevelScene());
if (false) // if user pressed 'o'
game.push(new MyOptionsScene());
if (false) // if user pressed 'q'
game.quit();
}
protected void render() {
// TODO
}
protected void wakeup(Object... args) {
// TODO
}
protected void destroy() {
// TODO
}
}
package mygame.scene;
import mygame.object.MyPlayer;
import org.unbiquitous.uImpala.engine.core.ContainerScene;
public class MyLevelScene extends ContainerScene {
public MyLevelScene() {
add(new MyPlayer(assets));
}
}
package mygame.object;
import org.unbiquitous.uImpala.engine.asset.AssetManager;
import org.unbiquitous.uImpala.engine.core.GameComponents;
import org.unbiquitous.uImpala.engine.core.GameObject;
import org.unbiquitous.uImpala.engine.core.GameRenderers;
import org.unbiquitous.uImpala.engine.core.Game;
public class MyPlayer extends GameObject {
public MyPlayer(AssetManager assets) {
// TODO
}
protected void update() {
if (false) // if user pressed 'q'
GameComponents.get(Game.class).quit();
}
protected void render(GameRenderers renderers) {
// TODO
}
protected void wakeup(Object... args) {
// TODO
}
protected void destroy() {
// TODO
}
}
package mygame.scene;
import org.unbiquitous.uImpala.engine.core.GameComponents;
import org.unbiquitous.uImpala.engine.core.GameScene;
import org.unbiquitous.uImpala.engine.core.Game;
public class MyOptionsScene extends GameScene {
public MyOptionsScene() {
// TODO
}
protected void update() {
if (false) // if user pressed 'esc'
GameComponents.get(Game.class).pop();
}
protected void render() {
// TODO
}
protected void wakeup(Object... args) {
// TODO
}
protected void destroy() {
// TODO
}
}
#Tutorial navigation
- [Previous: Basics 3 (Game components)](Basics 3 (Game components))
- Current: Basics 4 (Stack of scenes)
- [Next: Basics 5 (Rendering)](Basics 5 (Rendering))