Class GraphicEntityModule

java.lang.Object
com.codingame.gameengine.module.entities.GraphicEntityModule
All Implemented Interfaces:
Module

public class GraphicEntityModule extends Object implements Module

The GraphicEntityModule takes care of displaying and animating graphical entities on the replay of the game.

Use it by creating shapes, sprites, texts etc, then committing their states to a certain moment of the frame. By default, the states are commited automatically at the end of the frame.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    commitEntityState(double t, Entity<?>... entities)
    This entity's graphical counterpart, at instant t of the frame being computed, will have the same properties as the java object as it is now.
    void
    commitWorldState(double t)
    Creates a commit for each entity that has had some of its properties modified since a previous commit or the previous frame.
    Creates a new BitmapText entity, its graphical counterpart will be created on the frame currently being computed.
    createBufferedGroup(Entity<?>... entities)
    Creates a new BufferedGroup entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Circle entity, its graphical counterpart will be created on the frame currently being computed.
    createGroup(Entity<?>... entities)
    Creates a new Group entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Line entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Polygon entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Rectangle entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new RoundedRectangle entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Sprite entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Sprite animation, its graphical counterpart will be created on the frame currently being computed.
    Create a spritesheet splitter.
    Creates a new Text entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new Text entity, its graphical counterpart will be created on the frame currently being computed.
    Creates a new TilingSprite entity, its graphical counterpart will be created on the frame currently being computed.
    createWorld(int width, int height)
    Creates a new world data object to be used to compute all frames throughout the game.
     
    final void
    Called by the game manager after calling the Referee's gameTurn method.
    final void
    Called by the game manager after calling the Referee's onEnd method.
    final void
    Called by the game manager after calling the Referee's init method.

    Methods inherited from class java.lang.Object

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

    • createWorld

      public World createWorld(int width, int height)
      Creates a new world data object to be used to compute all frames throughout the game.

      This method may only be called once. This method may not be called after the frames have started being computed.

      The world's width and height determine how the positions of all entities are mapped onto the viewer.

      Parameters:
      width - The number of units across the width of the visible part of the game. Default is 1920.
      height - The number of units across the height of the visible part of the game. Default is 1080.
      Returns:
      the world data object.
      Throws:
      IllegalStateException - if the method is called more than once or after the game begins.
    • getWorld

      public World getWorld()
      Returns:
      the world data currently being used for computing frames
    • createSpriteSheetSplitter

      public SpriteSheetSplitter createSpriteSheetSplitter()
      Create a spritesheet splitter.
      Returns:
      a SpriteSheetSplitter
    • commitWorldState

      public void commitWorldState(double t)

      Creates a commit for each entity that has had some of its properties modified since a previous commit or the previous frame.

      This means that each one of those entities' graphical counterparts, at instant t of the frame being computed, will have the same properties as the java object as they are now.

      To force an entity to keep its current state instead of interpolating to the values of next frame, use commitEntityState instead.

      Only the most recent commits are kept for a given t.

      Parameters:
      t - The instant of the frame 0 ≤ t ≤ 1.
      Throws:
      IllegalArgumentException - if the t is not a valid instant.
    • commitEntityState

      public void commitEntityState(double t, Entity<?>... entities)
      This entity's graphical counterpart, at instant t of the frame being computed, will have the same properties as the java object as it is now.

      Only the most recent commit is kept for a given t.

      Parameters:
      t - The instant of the frame 0 ≤ t ≤ 1.
      entities - The entity objects to commit.
      Throws:
      IllegalArgumentException - if the t is not a valid instant or id entities is empty.
    • createCircle

      public Circle createCircle()
      Creates a new Circle entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createSprite

      public Sprite createSprite()
      Creates a new Sprite entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createLine

      public Line createLine()
      Creates a new Line entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createRectangle

      public Rectangle createRectangle()
      Creates a new Rectangle entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createRoundedRectangle

      public RoundedRectangle createRoundedRectangle()
      Creates a new RoundedRectangle entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createPolygon

      public Polygon createPolygon()
      Creates a new Polygon entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createText

      public Text createText(String string)
      Creates a new Text entity, its graphical counterpart will be created on the frame currently being computed.
      Parameters:
      string - The default string for the text. Can be changed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createText

      public Text createText()
      Creates a new Text entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createBitmapText

      public BitmapText createBitmapText()
      Creates a new BitmapText entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createGroup

      public Group createGroup(Entity<?>... entities)
      Creates a new Group entity, its graphical counterpart will be created on the frame currently being computed.

      A Group represents a collection of other entities. It acts as a container.

      Parameters:
      entities - 0 or more entities to immediately add to this group.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createBufferedGroup

      public BufferedGroup createBufferedGroup(Entity<?>... entities)
      Creates a new BufferedGroup entity, its graphical counterpart will be created on the frame currently being computed.

      A BufferedGroup acts like a group but uses its own rendering system to avoid rounding errors when its children are scaled up or down.

      Parameters:
      entities - 0 or more entities to immediately add to this group.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createSpriteAnimation

      public SpriteAnimation createSpriteAnimation()
      Creates a new Sprite animation, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • createTilingSprite

      public TilingSprite createTilingSprite()
      Creates a new TilingSprite entity, its graphical counterpart will be created on the frame currently being computed.
      Returns:
      the entity. Modify its properties to animate the graphical counterpart.
    • onGameInit

      public final void onGameInit()
      Description copied from interface: Module
      Called by the game manager after calling the Referee's init method. The module must be registered to the game manager.
      Specified by:
      onGameInit in interface Module
    • onAfterGameTurn

      public final void onAfterGameTurn()
      Description copied from interface: Module
      Called by the game manager after calling the Referee's gameTurn method. The module must be registered to the game manager.
      Specified by:
      onAfterGameTurn in interface Module
    • onAfterOnEnd

      public final void onAfterOnEnd()
      Description copied from interface: Module
      Called by the game manager after calling the Referee's onEnd method. The module must be registered to the game manager.
      Specified by:
      onAfterOnEnd in interface Module