Package playn.scene
Class ImageLayer
java.lang.Object
playn.scene.Layer
playn.scene.ImageLayer
- All Implemented Interfaces:
AutoCloseable
,Closeable
- Direct Known Subclasses:
CanvasLayer
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.-
Nested Class Summary
Nested classes/interfaces inherited from class playn.scene.Layer
Layer.HitTester, Layer.Origin, Layer.State, Layer.Visitor
Nested classes/interfaces inherited from interface react.Closeable
Closeable.Set, Closeable.Util
-
Field Summary
Modifier and TypeFieldDescriptionfloat
An explicit width and height for this layer.float
An explicit width and height for this layer.The subregion of the tile to render.Fields inherited from class playn.scene.Layer
DEBUG_RECTS, state
-
Constructor Summary
ConstructorDescriptionCreates a texture layer with no texture.ImageLayer
(Tile tile) Creates an image layer with the supplied texture tile.ImageLayer
(TileSource source) Obtains the tile fromsource
, asynchronously if necessary, and displays it. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Disposes this layer, removing it from its parent layer.float
height()
Returns the height of this layer.Setsregion
.setSize
(float width, float height) SetsforceWidth
andforceHeight
.setSize
(IDimension size) SetsforceWidth
andforceHeight
.setSource
(TileSource source) Sets the texture rendered by this layer to the texture provided bysource
.Sets the texture rendered by this layer.Sets the tile rendered by this layer to the asynchronous result oftile
.tile()
Returns the tile rendered by this layer.float
width()
Returns the width of this layer.Methods inherited from class playn.scene.Layer
absorbHits, alpha, debugPrint, depth, disposed, events, hasEventListeners, hitTest, hitTestDefault, interactive, name, onAdded, onDisposed, onRemoved, origin, origin, originX, originY, paint, parent, rotation, scale, scaledHeight, scaledWidth, scaleX, scaleY, setAlpha, setBatch, setDepth, setHitTester, setInteractive, setName, setOrigin, setOrigin, setRotation, setScale, setScale, setScaleX, setScaleY, setTint, setTranslation, setTranslation, setTx, setTy, setVisible, tint, toString, transform, translation, translation, tx, ty, visible, visit
-
Field Details
-
forceWidth
public float forceWidthAn 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 forceHeightAn 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
The subregion of the tile to render. If this isnull
(the default) the entire tile is rendered. IfforceWidth
orforceHeight
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
Creates an image layer with the supplied texture tile. -
ImageLayer
Obtains the tile fromsource
, 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
Returns the tile rendered by this layer. -
setTile
Sets the texture rendered by this layer. One can suppliednull
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
Sets the texture rendered by this layer to the texture provided bysource
. Ifsource
is not yet ready, the texture will be set when it becomes ready. Until then any previous texture will continue to be displayed. -
setTile
Sets the tile rendered by this layer to the asynchronous result oftile
. When the future completes, this layer's tile will be set. Until then, the current tile (if any) will continue to be rendered. -
setSize
SetsforceWidth
andforceHeight
.- Returns:
this
, for convenient call chaining.
-
setSize
SetsforceWidth
andforceHeight
.- Returns:
this
, for convenient call chaining.
-
setRegion
Setsregion
.- 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. -
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. -
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.
-