Package scene

Class Scene

java.lang.Object
scene.Scene
Direct Known Subclasses:
DemoPlatformer, DemoTopDown, TextRenderingDemo

public abstract class Scene extends Object
Author:
Asher Haun, Juyas, VoxelRifts

Abstract class encapsulating the game logic, the gameObjects, the renderers, the physics specifications and all the necessary ecs-related logic. Programming/Interacting with this game engine will usually involve the following boilerplate code:

     public class Main extends Scene {
         public static void main(String[] args) {
             Engine.init(1920, 1080, "Azurite Engine Demo In Comment", 1.0f);
             Engine.scenes().switchScene(new Main(), true);
             Engine.showWindow();
         }

         public void awake() {
             camera = new Camera();
             ...
         }

         public void update() {
             ...
         }
     }
 
A simple example of a scene with just a rendered sprite:
     public class Main extends Scene {
         GameObject player;
         Sprite s;

         public static void main(String[] args) {
             Engine.init(1920, 1080, "Azurite Engine Demo In Comment", 1.0f);
             Engine.scenes().switchScene(new Main(), true);
             Engine.showWindow();
         }

         public void awake() {
             camera = new Camera();

             player = new GameObject();
             s = new Sprite
             player.addComponent(new SpriteRenderer(s, new Vector2f(100)));
         }

         public void update() {
             if (Keyboard.getKeyDown(GLFW.GLFW_KEY_SPACE)) {
                 player.transform.add(new Vector2f(1, 0));
             }
         }
     }
 

See Also:
  • Field Details

  • Constructor Details

    • Scene

      public Scene()
  • Method Details

    • isActive

      public boolean isActive()
    • awake

      public void awake()
      Runs only once on startup, useful for initializing gameObjects or for first time setup.
    • activate

      public void activate()
      This method will be called each time this scene becomes active by SceneManager. Will be called right before the first update. Can be used to prepare the scene to be shown after been shown previously to reset to a certain state.
    • deactivate

      public void deactivate()
      This method will be called each time this scene becomes inactive by SceneManager, because of switching to another method or termination of the program. Can be used to preserve the current state of the scene or quickly complete/cancel tasks that were midst execution.
    • update

      public void update()
      This method is called every frame, and can be used to update objects.
    • postProcess

      public void postProcess(Texture texture)
      Apply post processing to a texture
      Parameters:
      texture - input texture
    • clean

      public void clean()
      This method is called at the end of the program
    • startUi

      public final void startUi()
    • startGameObjects

      public final void startGameObjects()
      Loops through all gameobjects already in the scene and calls their start methods.
    • getColliders

      public List<Collider> getColliders()
    • registerCollider

      public final void registerCollider(GameObject gameObject)
    • unregisterCollider

      public final void unregisterCollider(GameObject gameObject)
    • sceneId

      public final int sceneId()
      The sceneId is meant to represent the instance of a scene as an integer
      See Also:
    • getGameObjects

      public List<GameObject> getGameObjects()
      Returns:
      the List of gameObjects contained in the scene.
    • addGameObjectToScene

      public void addGameObjectToScene(GameObject gameObject)
      Parameters:
      gameObject - GameObject to be added. Add a new gameObject to the scene and immediately call its start method.
    • removeGameObjectFromScene

      public void removeGameObjectFromScene(GameObject gameObject)
      Parameters:
      gameObject - GameObject to be added.
    • registerRenderer

      public void registerRenderer(Renderer renderer)
      Register a renderer to this scene
      Parameters:
      renderer - the renderer to be registered
    • camera

      public Camera camera()
      Returns:
      Returns the scene's instance of Camera
    • updateGameObjects

      public void updateGameObjects()
      Loops through all the gameObjects in the scene and calls their update methods.
    • render

      public void render()
    • debugRender

      public void debugRender()
    • initRenderers

      public void initRenderers()
      Initialize all renderers
    • addUiObject

      public void addUiObject(Text t)
    • textRender

      public final void textRender()
    • updateUI

      public void updateUI()
    • addToRenderers

      public void addToRenderers(GameObject gameObject)
      Add a gameObject to all renderers
      Parameters:
      gameObject - the gameObject to be added