Package playn.scene

Class ImageLayer

java.lang.Object
playn.scene.Layer
playn.scene.ImageLayer
All Implemented Interfaces:
AutoCloseable, Closeable
Direct Known Subclasses:
CanvasLayer

public class ImageLayer extends Layer
A layer that displays a texture or region of a texture (tile). By default, the layer is the same size as its source, but its size can be changed from that default and the layer will either scale or repeat the texture to cause it to fill its bounds depending on the Texture it renders.
  • Field Details

    • forceWidth

      public float forceWidth
      An explicit width and height for this layer. If the width or height exceeds the underlying tile width or height, it will be scaled or repeated depending on the tile texture's repeat configuration in the pertinent axis. If either value is < 0 that indicates that the size of the tile being rendered should be used.

      Note: if you use these sizes in conjunction with a logical origin, you must set them via setSize(float, float) to cause the origin to be recomputed.

    • forceHeight

      public float forceHeight
      An explicit width and height for this layer. If the width or height exceeds the underlying tile width or height, it will be scaled or repeated depending on the tile texture's repeat configuration in the pertinent axis. If either value is < 0 that indicates that the size of the tile being rendered should be used.

      Note: if you use these sizes in conjunction with a logical origin, you must set them via setSize(float, float) to cause the origin to be recomputed.

    • region

      public Rectangle region
      The subregion of the tile to render. If this is null (the default) the entire tile is rendered. If forceWidth or forceHeight are not set, the width and height of this image layer will be the width and height of the supplied region.

      Note: when a subregion is configured, a texture will always be scaled, never repeated. If you want to repeat a texture, you have to use the whole texture. This is a limitation of OpenGL.

      Note: if you use this region in conjunction with a logical origin, you must set it via setRegion(pythagoras.f.Rectangle) to cause the origin to be recomputed.

  • Constructor Details

    • ImageLayer

      public ImageLayer(Tile tile)
      Creates an image layer with the supplied texture tile.
    • ImageLayer

      public ImageLayer(TileSource source)
      Obtains the tile from source, asynchronously if necessary, and displays it. If the source is not ready, this layer will display nothing until it becomes ready and delivers its tile.
    • ImageLayer

      public ImageLayer()
      Creates a texture layer with no texture. It will be invisible until a texture is set into it.
  • Method Details

    • tile

      public Tile tile()
      Returns the tile rendered by this layer.
    • setTile

      public ImageLayer setTile(Tile tile)
      Sets the texture rendered by this layer. One can supplied null to release and clear any texture currently being rendered and leave this layer in an uninitialized state. This isn't something one would normally do, but could be useful if one was free-listing image layers for some reason.
    • setSource

      public ImageLayer setSource(TileSource source)
      Sets the texture rendered by this layer to the texture provided by source. If source is not yet ready, the texture will be set when it becomes ready. Until then any previous texture will continue to be displayed.
    • setTile

      public ImageLayer setTile(RFuture<? extends Tile> tile)
      Sets the tile rendered by this layer to the asynchronous result of tile. When the future completes, this layer's tile will be set. Until then, the current tile (if any) will continue to be rendered.
    • setSize

      public ImageLayer setSize(float width, float height)
      Returns:
      this, for convenient call chaining.
    • setSize

      public ImageLayer setSize(IDimension size)
      Returns:
      this, for convenient call chaining.
    • setRegion

      public ImageLayer setRegion(Rectangle region)
      Sets region.
      Returns:
      this, for convenient call chaining.
    • width

      public float width()
      Description copied from class: Layer
      Returns the width of this layer. Note: not all layers know their size. Those that don't return 0.
      Overrides:
      width in class Layer
    • height

      public float height()
      Description copied from class: Layer
      Returns the height of this layer. Note: not all layers know their size. Those that don't return 0.
      Overrides:
      height in class Layer
    • close

      public void close()
      Description copied from class: Layer
      Disposes this layer, removing it from its parent layer. Any resources associated with this layer are freed, and it cannot be reused after being disposed. Disposing a layer that has children will dispose them as well.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class Layer