Class RenderEngine
public final class RenderEngine
extends java.lang.Object
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.
Field Summary
Fields Modifier and Type Field Description static float
DEFAULT_RENDERSCALE
Constructor Summary
Constructors Constructor Description RenderEngine()
You should never call this manually! Instead use theGame.graphics()
instance.Method Summary
Modifier and Type Method Description void
addEntityRenderedListener(EntityRenderedListener listener)
Adds the specified entity rendered listener to receive events when entities were rendered.void
addEntityRenderListener(EntityRenderListener listener)
Adds the specified entity render listener to receive events and callbacks about the rendering process of entities.boolean
canRender(IEntity entity)
Determines whether the specified entity can be rendered by evaluating the callbacks to all registeredEntityRenderListeners
.float
getBaseRenderScale()
Gets the base render scale of the game.void
removeEntityRenderedListener(EntityRenderedListener listener)
Removes the specified entity rendered listener.void
removeEntityRenderListener(EntityRenderListener listener)
Removes the specified entity render listener.void
renderEntities(java.awt.Graphics2D g, java.util.Collection<? extends IEntity> entities)
Renders the specified entities at their current location in the environment.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.void
renderEntity(java.awt.Graphics2D g, IEntity entity)
Renders the specified entity at its current location in the environment.void
renderImage(java.awt.Graphics2D g, java.awt.Image image, double x, double y)
Renders the specified image at the defined map location.void
renderImage(java.awt.Graphics2D g, java.awt.Image image, java.awt.geom.Point2D location)
Renders the specified image at the defined map location.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.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.void
renderOutline(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke)
Renders the outline with the definedStroke
of the specified shape to the translated location in the game world.void
renderOutline(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke, boolean antialiasing)
Renders the outline with the definedStroke
of the specified shape to the translated location in the game world.void
renderOutline(java.awt.Graphics2D g, java.awt.Shape shape, java.awt.Stroke stroke, boolean antialiasing, double angle)
Renders the outline with the definedStroke
of the specified shape to the translated location in the game world.void
renderShape(java.awt.Graphics2D g, java.awt.Shape shape)
Renders the specified shape to the translated location in the game world.void
renderShape(java.awt.Graphics2D g, java.awt.Shape shape, boolean antialiasing)
Renders the specified shape to the translated location in the game world.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.void
renderText(java.awt.Graphics2D g, java.lang.String text, double x, double y)
Renders the specified text to the defined map location.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.void
renderText(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location)
Renders the specified text to the defined map location.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.void
setBaseRenderScale(float scale)
Sets the global base scale that is used to calculate the actual render scale of the game.
Field Details
DEFAULT_RENDERSCALE
public static final float DEFAULT_RENDERSCALE- See Also:
- Constant Field Values
Constructor Details
RenderEngine
public RenderEngine()You should never call this manually! Instead use the
Game.graphics()
instance.- See Also:
Game.graphics()
Method Details
addEntityRenderedListener
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
Removes the specified entity rendered listener.- Parameters:
listener
- The listener to remove.
addEntityRenderListener
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
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 renderedx
- The x-coordinate of the text.y
- The y-coordinate of the textantialias
- 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 renderedx
- 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 definedStroke
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 definedStroke
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 definedStroke
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 theEntityYComparator
to simulate 2.5D graphics.- See Also:
EntityYComparator
renderEntity
Renders the specified entity at its current location in the environment.This method uses the
IEntityAnimationController
to render the appropriateAnimation
.
If the entity implements theIRenderable
interface, its render method is being called afterwards.To listen to events about this process, you can add a
EntityRenderListener
orEntityRenderedListener
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
Determines whether the specified entity can be rendered by evaluating the callbacks to all registeredEntityRenderListeners
.If the
RenderType
of the specified entity is set toNONE
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)