Package playn.scene

Class CanvasLayer

All Implemented Interfaces:
AutoCloseable, Closeable

public class CanvasLayer extends ImageLayer
Simplifies the process of displaying a Canvas which is updated after its initial creation. When modifying the canvas, one must call begin() to obtain a reference to the canvas, do the desired rendering, then call end() to upload the modified image data to the GPU for display by this layer.
  • Constructor Details

    • CanvasLayer

      public CanvasLayer(Graphics gfx, IDimension size)
      Creates a canvas layer with a backing canvas of size (in display units). This layer will display nothing until a begin()/end() pair is used to render something to its backing canvas.
    • CanvasLayer

      public CanvasLayer(Graphics gfx, float width, float height)
      Creates a canvas layer with a backing canvas of size width x height (in display units). This layer will display nothing until a begin()/end() pair is used to render something to its backing canvas.
    • CanvasLayer

      public CanvasLayer(Graphics gfx, Canvas canvas)
      Creates a canvas layer with the supplied backing canvas. The canvas will immediately be uploaded to the GPU for display.
  • Method Details

    • resize

      public void resize(float width, float height)
      Resizes the canvas that is displayed by this layer.

      Note: this throws away the old canvas and creates a new blank canvas with the desired size. Thus this should immediately be followed by a begin()/end() pair which updates the contents of the new canvas. Until then, it will display the old image data.

    • begin

      public Canvas begin()
      Starts a drawing operation on this layer's backing canvas. Thus must be follwed by a call to end() when the drawing is complete.
    • end

      public void end()
      Informs this layer that a drawing operation has just completed. The backing canvas image data is uploaded to the GPU.
    • setTile

      public ImageLayer setTile(Tile tile)
      Description copied from class: ImageLayer
      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.
      Overrides:
      setTile in class ImageLayer
    • setTile

      public ImageLayer setTile(RFuture<? extends Tile> tile)
      Description copied from class: ImageLayer
      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.
      Overrides:
      setTile in class ImageLayer
    • 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 ImageLayer
    • 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 ImageLayer
    • 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 ImageLayer