Class RenderEngine

java.lang.Object
de.gurkenlabs.litiengine.graphics.RenderEngine

public final class RenderEngine
extends java.lang.Object
The 2D Render Engine is used to render texts, shapes and entities at their location in the Environment and with respect to the Camera location and zoom.

Internally, it uses the static renderer implementations to actually execute the rendering process. This class basically prepares the specified render subject and passed them to a renderer with the current correct context.

See Also:
GameWorld.environment(), GameWorld.camera(), IEntity.getLocation(), ShapeRenderer, TextRenderer, ImageRenderer
  • Field Summary

    Fields 
    Modifier and TypeFieldDescription
    static floatDEFAULT_RENDERSCALE 
  • Constructor Summary

    Constructors 
    ConstructorDescription
    RenderEngine()
    You should never call this manually! Instead use the Game.graphics() instance.
  • Method Summary

    Modifier and TypeMethodDescription
    voidaddEntityRenderedListener​(EntityRenderedListener listener)
    Adds the specified entity rendered listener to receive events when entities were rendered.
    voidaddEntityRenderListener​(EntityRenderListener listener)
    Adds the specified entity render listener to receive events and callbacks about the rendering process of entities.
    booleancanRender​(IEntity entity)
    Determines whether the specified entity can be rendered by evaluating the callbacks to all registered EntityRenderListeners.
    floatgetBaseRenderScale()
    Gets the base render scale of the game.
    voidremoveEntityRenderedListener​(EntityRenderedListener listener)
    Removes the specified entity rendered listener.
    voidremoveEntityRenderListener​(EntityRenderListener listener)
    Removes the specified entity render listener.
    voidrenderEntities​(java.awt.Graphics2D g, java.util.Collection<? extends IEntity> entities)
    Renders the specified entities at their current location in the environment.
    voidrenderEntities​(java.awt.Graphics2D g, java.util.Collection<? extends IEntity> entities, boolean sort)
    Renders the specified entities at their current location in the environment.
    voidrenderEntity​(java.awt.Graphics2D g, IEntity entity)
    Renders the specified entity at its current location in the environment.
    voidrenderImage​(java.awt.Graphics2D g, java.awt.Image image, double x, double y)
    Renders the specified image at the defined map location.
    voidrenderImage​(java.awt.Graphics2D g, java.awt.Image image, java.awt.geom.Point2D location)
    Renders the specified image at the defined map location.
    voidrenderOutline​(java.awt.Graphics2D g, java.awt.Shape shape)
    Renders the outline of the specified shape to the translated location in the game world.
    voidrenderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing)
    Renders the outline of the specified shape to the translated location in the game world.
    voidrenderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke)
    Renders the outline with the defined Stroke of the specified shape to the translated location in the game world.
    voidrenderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke, boolean antialiasing)
    Renders the outline with the defined Stroke of the specified shape to the translated location in the game world.
    voidrenderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke, boolean antialiasing, double angle)
    Renders the outline with the defined Stroke of the specified shape to the translated location in the game world.
    voidrenderShape​(java.awt.Graphics2D g, java.awt.Shape shape)
    Renders the specified shape to the translated location in the game world.
    voidrenderShape​(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing)
    Renders the specified shape to the translated location in the game world.
    voidrenderShape​(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing, double angle)
    Renders the specified shape to the translated location in the game world.
    voidrenderText​(java.awt.Graphics2D g, java.lang.String text, double x, double y)
    Renders the specified text to the defined map location.
    voidrenderText​(java.awt.Graphics2D g, java.lang.String text, double x, double y, boolean antialias)
    Renders the specified text to the defined map location.
    voidrenderText​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location)
    Renders the specified text to the defined map location.
    voidrenderText​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, boolean antialias)
    Renders the specified text to the defined map location.
    voidsetBaseRenderScale​(float scale)
    Sets the global base scale that is used to calculate the actual render scale of the game.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RenderEngine

      public RenderEngine()

      You should never call this manually! Instead use the Game.graphics() instance.

      See Also:
      Game.graphics()
  • Method Details

    • addEntityRenderedListener

      public void addEntityRenderedListener​(EntityRenderedListener listener)
      Adds the specified entity rendered listener to receive events when entities were rendered.

      This is the global equivalent to IEntity.addEntityRenderedListener

      Parameters:
      listener - The listener to add.
      See Also:
      IEntity.onRendered(EntityRenderedListener)
    • removeEntityRenderedListener

      public void removeEntityRenderedListener​(EntityRenderedListener listener)
      Removes the specified entity rendered listener.
      Parameters:
      listener - The listener to remove.
    • addEntityRenderListener

      public void addEntityRenderListener​(EntityRenderListener listener)
      Adds the specified entity render listener to receive events and callbacks about the rendering process of entities.

      This is the global equivalent to IEntity.addEntityRenderListener

      Parameters:
      listener - The listener to add.
      See Also:
      IEntity.addEntityRenderListener(EntityRenderListener)
    • removeEntityRenderListener

      public void removeEntityRenderListener​(EntityRenderListener listener)
      Removes the specified entity render listener.
      Parameters:
      listener - The listener to remove.
    • getBaseRenderScale

      public float getBaseRenderScale()
      Gets the base render scale of the game.
      Returns:
      The base render scale.
    • setBaseRenderScale

      public void setBaseRenderScale​(float scale)
      Sets the global base scale that is used to calculate the actual render scale of the game.
      Parameters:
      scale - The base render scale for the game.
      See Also:
      ICamera.getRenderScale()
    • renderText

      public void renderText​(java.awt.Graphics2D g, java.lang.String text, double x, double y, boolean antialias)
      Renders the specified text to the defined map location.
      Parameters:
      g - The graphics object to render on.
      text - The text to be rendered
      x - The x-coordinate of the text.
      y - The y-coordinate of the text
      antialias - Configure whether or not to render the text with antialiasing.
    • renderText

      public void renderText​(java.awt.Graphics2D g, java.lang.String text, double x, double y)
      Renders the specified text to the defined map location.
      Parameters:
      g - The graphics object to render on.
      text - The text to be rendered
      x - The x-coordinate of the text.
      y - The y-coordinate of the text
    • renderText

      public void renderText​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, boolean antialias)
      Renders the specified text to the defined map location.
      Parameters:
      g - The graphics object to render on.
      text - The text to be rendered.
      location - The location on the map.
      antialias - Configure whether or not to render the text with antialiasing.
    • renderText

      public void renderText​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location)
      Renders the specified text to the defined map location.
      Parameters:
      g - The graphics object to render on.
      text - The text to be rendered.
      location - The location on the map.
    • renderShape

      public void renderShape​(java.awt.Graphics2D g, java.awt.Shape shape)
      Renders the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
    • renderShape

      public void renderShape​(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing)
      Renders the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
      antialiasing - Configure whether or not to render the shape with antialiasing.
    • renderShape

      public void renderShape​(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing, double angle)
      Renders the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
      antialiasing - Configure whether or not to render the shape with antialiasing.
      angle - The angle by which the shape will be rotated.
    • renderOutline

      public void renderOutline​(java.awt.Graphics2D g, java.awt.Shape shape)
      Renders the outline of the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
    • renderOutline

      public void renderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing)
      Renders the outline of the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
      antialiasing - Configure whether or not to render the shape with antialiasing.
    • renderOutline

      public void renderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke)
      Renders the outline with the defined Stroke of the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
      stroke - The stroke that is used to render the shape.
      See Also:
      Stroke
    • renderOutline

      public void renderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke, boolean antialiasing)
      Renders the outline with the defined Stroke of the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
      stroke - The stroke that is used to render the shape.
      antialiasing - Configure whether or not to render the shape with antialiasing.
      See Also:
      Stroke
    • renderOutline

      public void renderOutline​(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke, boolean antialiasing, double angle)
      Renders the outline with the defined Stroke of the specified shape to the translated location in the game world.
      Parameters:
      g - The graphics object to render on.
      shape - The shape to be rendered.
      stroke - The stroke that is used to render the shape.
      antialiasing - Configure whether or not to render the shape with antialiasing.
      angle - The angle by which the shape will be rotated.
      See Also:
      Stroke
    • renderImage

      public void renderImage​(java.awt.Graphics2D g, java.awt.Image image, double x, double y)
      Renders the specified image at the defined map location.
      Parameters:
      g - The graphics object to render on.
      image - The image to be rendered.
      x - The x-coordinate of the image.
      y - The y-coordinate of the image
    • renderImage

      public void renderImage​(java.awt.Graphics2D g, java.awt.Image image, java.awt.geom.Point2D location)
      Renders the specified image at the defined map location.
      Parameters:
      g - The graphics object to render on.
      image - The image to be rendered.
      location - The location of the image.
    • renderEntities

      public void renderEntities​(java.awt.Graphics2D g, java.util.Collection<? extends IEntity> entities)
      Renders the specified entities at their current location in the environment.
      Parameters:
      g - The graphics object to render on.
      entities - The entities to be rendered.
    • renderEntities

      public void renderEntities​(java.awt.Graphics2D g, java.util.Collection<? extends IEntity> entities, boolean sort)
      Renders the specified entities at their current location in the environment.

      This method sorts the specified entities by their y-coordinate unless the sort parameter is set to false.

      Parameters:
      g - The graphics object to render on.
      entities - The entities to be rendered.
      sort - Defines whether the entities should be sorted by the EntityYComparator to simulate 2.5D graphics.
      See Also:
      EntityYComparator
    • renderEntity

      public void renderEntity​(java.awt.Graphics2D g, IEntity entity)
      Renders the specified entity at its current location in the environment.

      This method uses the IEntityAnimationController to render the appropriate Animation.
      If the entity implements the IRenderable interface, its render method is being called afterwards.

      To listen to events about this process, you can add a EntityRenderListener or EntityRenderedListener to the render engine.

      Parameters:
      g - The graphics object to render on.
      entity - The entity to be rendered.
      See Also:
      IEntity.animations(), IAnimationController.getCurrentImage(), IRenderable.render(Graphics2D), canRender(IEntity), EntityRenderListener.canRender(IEntity), EntityRenderedListener.rendered(EntityRenderEvent)
    • canRender

      public boolean canRender​(IEntity entity)
      Determines whether the specified entity can be rendered by evaluating the callbacks to all registered EntityRenderListeners.

      If the RenderType of the specified entity is set to NONE or there are any callbacks that prevent the entity from being rendered, this method will return false.

      Parameters:
      entity - The entity to check whether it can be rendered or not.
      Returns:
      True if the entity can be rendered; otherwise false.
      See Also:
      IEntity.getRenderType(), RenderType.NONE, EntityRenderListener.canRender(IEntity)