Creates a new MeshStyle instance. Subclasses must provide a constructor that can be called without any arguments.
Changes the color of all vertices to the same value. The getter simply returns the color of the first vertex.
Returns a reference to the index data of the assigned target (or null
if there is no target). Beware: the style itself does not own any indices;
it is limited to manipulating those of the target mesh.
The target the style is currently assigned to.
The texture that is mapped to the mesh (or null
, if there is none).
Indicates if pixels at the edges will be repeated or clamped. Only works for power-of-two textures. @default false
The smoothing filter that is used for the texture. @default bilinear
The actual class of this style.
Returns a reference to the vertex data of the assigned target (or null
if there is no target). Beware: the style itself does not own any vertices;
it is limited to manipulating those of the target mesh.
The format used to store the vertices.
The vertex format expected by this style (the same as found in the MeshEffect-class).
Copies the index data of the style's current target to the target of another style. The given offset value will be added to all indices during the process.
This method is used when batching meshes together for rendering. The parameter
targetStyle
will point to the style of a MeshBatch
(a
subclass of Mesh
). Subclasses may override this method if they need
to modify the index data in that process.
Copies the vertex data of the style's current target to the target of another style. If you pass a matrix, all vertices will be transformed during the process.
This method is used when batching meshes together for rendering. The parameter
targetStyle
will point to the style of a MeshBatch
(a
subclass of Mesh
). Subclasses may override this method if they need
to modify the vertex data in that process.
Indicates if the current instance can be batched with the given style. To be overridden by subclasses if default behavior is not sufficient. The base implementation just checks if the styles are of the same type and if the textures are compatible.
Creates a clone of this instance. The method will work for subclasses automatically, no need to override it.
Copies all properties of the given style to the current instance (or a subset, if the classes don't match). Must be overridden by all subclasses!
Creates the effect that does the actual, low-level rendering. To be overridden by subclasses!
Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.
Dispatches an event with the given parameters to all objects that have registered listeners for the given type. The method uses an internal pool of event objects to avoid allocations.
Returns the texture coordinates of the vertex at the specified index.
Returns the alpha value of the vertex at the specified index.
Returns the RGB color of the vertex at the specified index.
The position of the vertex at the specified index, in the mesh's local coordinate system.
Only modify the position of a vertex if you know exactly what you're doing, as
some classes might not work correctly when their vertices are moved. E.g. the
Quad
class expects its vertices to spawn up a perfectly rectangular
area; some of its optimized methods won't work correctly if that premise is no longer
fulfilled or the original bounds change.
If called with one argument, figures out if there are any listeners registered for the given event type. If called with two arguments, also determines if a specific listener is registered.
Removes all event listeners with a certain type, or all of them if type is null. Be careful when removing all event listeners: you never know who else was listening.
Sets the texture coordinates of the vertex at the specified index to the given values.
Sets the alpha value of the vertex at the specified index to a certain value.
Sets the RGB color of the vertex at the specified index to a certain value.
Updates the settings of the given effect to match the current style.
The given effect
will always match the class returned by
createEffect
.
To be overridden by subclasses!
Generated using TypeDoc
MeshStyles provide a means to completely modify the way a mesh is rendered. The base class provides Starling's standard mesh rendering functionality: colored and (optionally) textured meshes. Subclasses may add support for additional features like color transformations, normal mapping, etc.
Using styles
First, create an instance of the desired style. Configure the style by updating its properties, then assign it to the mesh. Here is an example that uses a fictitious
ColorStyle
:Beware:
Creating your own styles
To create custom rendering code in Starling, you need to extend two classes:
MeshStyle
andMeshEffect
. While the effect class contains the actual AGAL rendering code, the style provides the API that other developers will interact with.Subclasses of
MeshStyle
will add specific properties that configure the style's outcome, like theredOffset
andredMultiplier
properties in the sample above. Here's how to properly create such a class:copyFrom
— that's necessary for batching.createEffect
— this method must return theMeshEffect
that will do the actual Stage3D rendering.updateEffect
— this configures the effect created above right before rendering.canBatchWith
if necessary — this method figures out if one instance of the style can be batched with another. If they all can, you can leave this out.If the style requires a custom vertex format, you must also:
VERTEX_FORMAT
to the class andget vertexFormat
and let it return exactly that format.When that's done, you can turn to the implementation of your
MeshEffect
; thecreateEffect
-override will return an instance of this class. Directly before rendering begins, Starling will then callupdateEffect
to set it up.@see starling.rendering.MeshEffect @see starling.rendering.VertexDataFormat @see starling.display.Mesh