Skip to content

Lua API: 4. RenderLayer

MCUmbrella edited this page Nov 28, 2023 · 2 revisions

RenderLayer

RenderLayer is a container that stores RenderEntities. It differs from Photoshop's layers in that you can only manipulate RenderEntity objects through it, not directly pixels.

Member functions

getOrder

Get the order of the layer.

Return: Integer value, which indicates the order.

Example:

layer0 = RenderManager.getLayer(0)
Runtime.log("The order of the default layer is: " .. layer0:getOrder())

addEntity

Add an entity to the layer.

Parameter:

  • String texturePath: The path to a loaded texture that the entity uses. Starts from "(user project folder)/assets/textures/".

Return: The instance of the created entity.

Throw:

  • EngineException: when
    • the texture has failed to load

NOTE: Newly created entities are always located in the upper left corner (x=0, y=0).

addText

Add a text entity to the layer.

Parameter:

  • String content: The text content to be shown.
  • String fontName (optional): The name of the loaded font to use. Default is empty string.
  • Number pt (optional): Integer, which indicates the size of the font to be used. Default is 32.

Return: The instance of the created text entity.

Throw:

  • EngineException: when
    • there's no loaded font with that name
    • parameter 'pt' is not positive

removeEntity

Remove an entity from the layer.

Parameter:

  • Number id: The ID of the entity.

Throw:

  • EngineException: when
    • the entity with the specified ID doesn't exist

getEntity

Get an entity by its ID.

Parameter:

  • Number id: The ID of the entity.

Return: The entity with the specified ID.

Throw:

  • EngineException: when
    • the entity with the specified ID doesn't exist

hasEntity

Check if an entity with the specified ID exists.

Parameter:

  • Number id: The ID of the entity.

Return: true if so, false otherwise.

size

How many entities does the layer have?

Return: Integer indicating the total number of entities (including text entities) in the layer.

clear

Remove all entities in the layer.