The source code for this document can be found here.
A Layer is a specialized TileGraphics object which can be drawn upon a Layerable object. A Layer differs from a TileGraphics in the way it is handled. It can be repositioned relative to its parent while a TileGraphics cannot. Both Layers and TileGraphics are in-memory objects which are drawn only when the underlying Layerable object is drawn. Another important difference is that when a TileGraphics is drawn it is a copy operation (it won’t change the graphics itself), while a Layer is placed over other Layers and the TileGrid. Zircon supports transparency, which means that all Layers are visible.
TileGrid tileGrid = LibgdxApplications.startTileGrid(AppConfig.newBuilder() .withSize(20, 10) .build()); Layer layer0 = Layer.newBuilder() .withTileGraphics(DrawSurfaces.tileGraphicsBuilder() .withSize(3, 3) .withFiller(Tile.newBuilder() .withForegroundColor(ANSITileColor.GREEN) .withBackgroundColor(TileColor.transparent()) .withCharacter('X') .build()) .build()) .withOffset(1, 1) .build(); Layer layer1 = Layer.newBuilder() .withTileGraphics(DrawSurfaces.tileGraphicsBuilder() .withSize(3, 3) .withFiller(Tile.newBuilder() .withForegroundColor(ANSITileColor.RED) .withBackgroundColor(TileColor.transparent()) .withCharacter('+') .build()) .build()) .withOffset(3, 3) .build(); tileGrid.addLayer(layer0); tileGrid.addLayer(layer1);
After running this code you’ll see this on your screen:
Note that in the above example all objects are created by using the corresponding factory methods in Layer, DrawSurfaces and Tile. This is a common pattern in Zircon and you should use
these Builders for creating all Zircon objects. Read about The design philosophy behind Zircon for more info.
Changes in your Layers (like their position) is automatically handled and visible on the screen.