java.lang.AutoCloseable, react.CloseableClippedLayer, ImageLayerpublic abstract class Layer
extends java.lang.Object
implements react.Closeable
paint(playn.core.Surface)ed.
Everything can be accomplished by extending Layer and overriding paintImpl(playn.core.Surface).
However, GroupLayer, ImageLayer, ClippedLayer etc. are provided to
make it easy to implement common use cases "out of the box".
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
Layer.HitTester |
Used to customize a layer's hit testing mechanism.
|
static class |
Layer.Origin |
Used to configure the origin of a layer based on its width/height.
|
static class |
Layer.State |
Enumerates layer lifecycle states; see
state. |
static interface |
Layer.Visitor |
| Modifier and Type | Field | Description |
|---|---|---|
static boolean |
DEBUG_RECTS |
Controls rendering of debug rectangles around views.
|
react.ValueView<Layer.State> |
state |
A reactive value which tracks this layer's lifecycle.
|
| Constructor | Description |
|---|---|
Layer() |
Creates an unclipped layer.
|
| Modifier and Type | Method | Description |
|---|---|---|
Layer |
absorbHits() |
Configures a hit tester for this layer which hits this layer any time a hit does not hit a
child of this layer.
|
float |
alpha() |
Return the global alpha value for this layer.
|
void |
close() |
Disposes this layer, removing it from its parent layer.
|
void |
debugPrint(playn.core.Log log) |
Prints a debug representation of this layer and its children.
|
float |
depth() |
Returns this layer's current depth.
|
boolean |
disposed() |
Whether this layer has been disposed.
|
react.Signal<java.lang.Object> |
events() |
Returns a signal via which events may be dispatched "on" this layer.
|
boolean |
hasEventListeners() |
Returns true if
events has at least one listener. |
float |
height() |
Returns the height of this layer.
|
Layer |
hitTest(pythagoras.f.Point p) |
Tests whether the supplied (layer relative) point "hits" this layer or any of its children.
|
Layer |
hitTestDefault(pythagoras.f.Point p) |
Like
hitTest(pythagoras.f.Point) except that it ignores a configured Layer.HitTester. |
boolean |
interactive() |
Returns whether this layer reacts to clicks and touches.
|
java.lang.String |
name() |
Returns the name of this layer.
|
void |
onAdded(react.SignalView.Listener<? super Layer> action) |
Connects
action to state such that it is triggered when this layer is added
to a rooted scene graph. |
void |
onDisposed(react.SignalView.Listener<? super Layer> action) |
Connects
action to state such that it is triggered when this layer is
disposed. |
void |
onRemoved(react.SignalView.Listener<? super Layer> action) |
Connects
action to state such that it is triggered when this layer is
removed from a rooted scene graph. |
pythagoras.f.Point |
origin(pythagoras.f.Point into) |
Writes this layer's origin into
into. |
pythagoras.f.Vector |
origin(pythagoras.f.Vector into) |
Writes this layer's origin into
into. |
float |
originX() |
Returns the x-component of the layer's origin.
|
float |
originY() |
Returns the y-component of the layer's origin.
|
void |
paint(playn.core.Surface surf) |
Renders this layer to
surf, including its children. |
GroupLayer |
parent() |
Returns the layer that contains this layer, or
null. |
float |
rotation() |
Returns this layer's current rotation.
|
pythagoras.f.Vector |
scale(pythagoras.f.Vector into) |
Writes this layer's scale into
into. |
float |
scaledHeight() |
Returns the height of the layer multiplied by its y scale.
|
float |
scaledWidth() |
Returns the width of the layer multiplied by its x scale.
|
float |
scaleX() |
Returns this layer's current scale in the x direction.
|
float |
scaleY() |
Returns this layer's current scale in the y direction.
|
Layer |
setAlpha(float alpha) |
Sets the alpha component of this layer's current tint.
|
Layer |
setBatch(playn.core.QuadBatch batch) |
Configures a custom batch (i.e.
|
Layer |
setDepth(float depth) |
Sets the depth of this layer.
|
Layer |
setHitTester(Layer.HitTester tester) |
Configures a custom hit tester for this layer.
|
Layer |
setInteractive(boolean interactive) |
Configures this layer as reactive to clicks and touches, or not.
|
void |
setName(java.lang.String name) |
Sets the name of this layer.
|
Layer |
setOrigin(float x,
float y) |
Sets the origin of the layer to a fixed position.
|
Layer |
setOrigin(Layer.Origin origin) |
Configures the origin of this layer based on a logical location which is recomputed whenever
the layer changes size.
|
Layer |
setRotation(float angle) |
Sets the current rotation of this layer, in radians.
|
Layer |
setScale(float scale) |
Sets the current x and y scale of this layer to
scale.. |
Layer |
setScale(float sx,
float sy) |
Sets the current x and y scale of this layer.
|
Layer |
setScaleX(float sx) |
Sets the current x scale of this layer.
|
Layer |
setScaleY(float sy) |
Sets the current y scale of this layer.
|
Layer |
setTint(int tint) |
Sets the tint for this layer, as
ARGB. |
Layer |
setTranslation(float x,
float y) |
Sets the x and y translation of this layer.
|
Layer |
setTranslation(pythagoras.f.XY trans) |
A variant of
setTranslation(float,float) that takes an XY. |
Layer |
setTx(float x) |
Sets the x translation of this layer.
|
Layer |
setTy(float y) |
Sets the y translation of this layer.
|
Layer |
setVisible(boolean visible) |
Configures this layer's visibility: if true, it will be rendered as normal, if false it and
its children will not be rendered.
|
int |
tint() |
Returns the current tint for this layer, as
ARGB. |
java.lang.String |
toString() |
|
pythagoras.f.AffineTransform |
transform() |
Returns the layer's current transformation matrix.
|
pythagoras.f.Point |
translation(pythagoras.f.Point into) |
Writes this layer's translation into
into. |
pythagoras.f.Vector |
translation(pythagoras.f.Vector into) |
Writes this layer's translation into
into. |
float |
tx() |
Returns this layer's current translation in the x direction.
|
float |
ty() |
Returns this layer's current translation in the y direction.
|
boolean |
visible() |
Returns true if this layer is visible (i.e.
|
void |
visit(Layer.Visitor visitor) |
Visits this layer and its children, in depth first order, with
visitor. |
float |
width() |
Returns the width of this layer.
|
public static boolean DEBUG_RECTS
public final react.ValueView<Layer.State> state
Layer.State.REMOVED, and
transitions to Layer.State.ADDED when the layer is added to a scene graph root and back to
Layer.State.REMOVED when removed, until it is finally close()d at which point it
transitions to Layer.State.DISPOSED.public Layer()
paint(playn.core.Surface) method must be overridden by the creator.public java.lang.String name()
setName(java.lang.String).public void setName(java.lang.String name)
name.public GroupLayer parent()
null.public react.Signal<java.lang.Object> events()
Dispatcher
mechanism uses this to dispatch (and listen for) mouse, pointer and touch events to the layers
affected by them. A game can also use this to dispatch any other kinds of events on a
per-layer basis, with the caveat that all listeners are notified of every event and each must
do a type test on the event to determine whether it matches.
Also, any layer that has one or more listeners on its events signal is marked as interactive(). Further, any GroupLayer which has one or more interactive children is
also marked as interactive. This allows Dispatchers to be more efficient in their
dispatching of UI events.
public boolean hasEventListeners()
events has at least one listener. Use this instead of calling Reactor.hasConnections() on events because events is created lazily this method
avoids creating it unnecessarily.public boolean interactive()
hitTest(pythagoras.f.Point), which forms the basis for the click and touch processing
provided by the Dispatchers.public Layer setInteractive(boolean interactive)
events signal.
A GroupLayer will be made non-interactive automatically if an event is dispatched
to it and it discovers that it no longer has any interactive children. Manual management of
interactivity is thus generally only useful for "leaf" nodes in the scene graph.
public boolean visible()
public Layer setVisible(boolean visible)
public boolean disposed()
public void onAdded(react.SignalView.Listener<? super Layer> action)
action to state such that it is triggered when this layer is added
to a rooted scene graph.public void onRemoved(react.SignalView.Listener<? super Layer> action)
action to state such that it is triggered when this layer is
removed from a rooted scene graph.public void onDisposed(react.SignalView.Listener<? super Layer> action)
action to state such that it is triggered when this layer is
disposed.public void close()
close in interface java.lang.AutoCloseableclose in interface react.Closeablepublic pythagoras.f.AffineTransform transform()
Note: any direct modifications to this matrix except modifications to its
translation, will be overwritten if a call is subsequently made to setScale(float),
setScale(float,float), setScaleX(float), setScaleY(float) or setRotation(float).
If you intend to manipulate a layer's transform matrix directly, do not call those
other methods. Also do not expect scaleX, scaleY, or rotation to
reflect the direct changes you've made to the transform matrix. They will not.
public float alpha()
The global alpha value for a layer controls the opacity of the layer but does not affect
the current drawing operation. I.e., when Game.paint is called and the Layer
is drawn, this alpha value is applied to the alpha channel of the Layer.
By default, the alpha for a Layer is 1.0 (not transparent).
public Layer setAlpha(float alpha)
setTint(int).
Values outside the range [0,1] will be clamped to the range [0,1].
alpha - alpha value in range [0,1] where 0 is transparent and 1 is opaque.public int tint()
ARGB.public Layer setTint(int tint)
ARGB.
NOTE: this will overwrite any value configured via setAlpha(float). Either
include your desired alpha in the high bits of tint or call setAlpha(float) after
calling this method.
NOTE: the RGB components of a layer's tint only work on GL-based backends. It is not possible to tint layers using the HTML5 canvas and Flash backends.
The tint for a layer controls the opacity of the layer but does not affect the current
drawing operation. I.e., when Game.paint is called and the Layer is drawn,
this tint is applied when rendering the layer.
public float originX()
public float originY()
public pythagoras.f.Point origin(pythagoras.f.Point into)
into.into for easy call chaining.public pythagoras.f.Vector origin(pythagoras.f.Vector into)
into.into for easy call chaining.public Layer setOrigin(float x, float y)
Layer.Origin.FIXED.x - origin on x axis in display units.y - origin on y axis in display units.public Layer setOrigin(Layer.Origin origin)
public float depth()
public Layer setDepth(float depth)
Within a single GroupLayer, layers are rendered from lowest depth to highest depth.
public float tx()
public float ty()
public pythagoras.f.Point translation(pythagoras.f.Point into)
into.into for easy call chaining.public pythagoras.f.Vector translation(pythagoras.f.Vector into)
into.into for easy call chaining.public Layer setTx(float x)
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
public Layer setTy(float y)
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
public Layer setTranslation(float x, float y)
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
public Layer setTranslation(pythagoras.f.XY trans)
setTranslation(float,float) that takes an XY.public float scaleX()
Note: this is the most recent value supplied to setScale(float) or
setScale(float,float), it is not extracted from the underlying transform.
Thus the sign of the scale returned by this method is preserved. It's also substantially
cheaper than extracting the scale from the affine transform matrix. This also means that if
you change the scale directly on the transform that scale will not be
returned by this method.
public float scaleY()
Note: this is the most recent value supplied to setScale(float) or
setScale(float,float), it is not extracted from the underlying transform.
Thus the sign of the scale returned by this method is preserved. It's also substantially
cheaper than extracting the scale from the affine transform matrix. This also means that if
you change the scale directly on the transform that scale will not be
returned by this method.
public pythagoras.f.Vector scale(pythagoras.f.Vector into)
into.into for easy call chaining.public Layer setScale(float scale)
scale.. Note that a scale of 1
is equivalent to no scale.
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
scale - non-zero scale value.public Layer setScaleX(float sx)
1 is equivalent to no
scale.
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
sx - non-zero scale value.public Layer setScaleY(float sy)
1 is equivalent to no
scale.
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
sy - non-zero scale value.public Layer setScale(float sx, float sy)
1 is equivalent to
no scale.
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
sx - non-zero scale value for the x axis.sy - non-zero scale value for the y axis.public float rotation()
Note: this is the most recent value supplied to setRotation(float), it is
not extracted from the underlying transform. Thus the value may lie outside the
range [-pi, pi] and the most recently set value is preserved. It's also substantially cheaper
than extracting the rotation from the affine transform matrix. This also means that if you
change the scale directly on the transform that rotation will not be
returned by this method.
public Layer setRotation(float angle)
setOrigin(float, float).
Note: all transform changes are deferred until transform is called
(which happens during rendering, if not before) at which point the current scale, rotation and
translation are composed into an affine transform matrix. This means that, for example,
setting rotation and then setting scale will not flip the rotation like it would were these
applied to the transform matrix one operation at a time.
angle - angle to rotate, in radians.public float width()
public float height()
public float scaledWidth()
public float scaledHeight()
public Layer hitTest(pythagoras.f.Point p)
Note that this method mutates the supplied point. If a layer is hit, the point will contain the original point as translated into that layer's coordinate system. If no layer is hit, the point will be changed to an undefined value.
public Layer hitTestDefault(pythagoras.f.Point p)
hitTest(pythagoras.f.Point) except that it ignores a configured Layer.HitTester. This allows one
to configure a hit tester which checks custom properties and then falls back on the default
hit testing implementation.public Layer setHitTester(Layer.HitTester tester)
public Layer absorbHits()
public Layer setBatch(playn.core.QuadBatch batch)
public void visit(Layer.Visitor visitor)
visitor.public void debugPrint(playn.core.Log log)
log - the output will go to this log (at the debug level).public final void paint(playn.core.Surface surf)
surf, including its children.public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2018. All Rights Reserved.