Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MeshStyle

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:

image:Image = new Image(heroTexture); colorStyle:ColorStyle = new ColorStyle(); colorStyle.redOffset = 0.5; colorStyle.redMultiplier = 2.0; image.style = colorStyle;

Beware:

  • A style instance may only be used on one object at a time.
  • A style might require the use of a specific vertex format; when the style is assigned, the mesh is converted to that format.

Creating your own styles

To create custom rendering code in Starling, you need to extend two classes: MeshStyle and MeshEffect. 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 the redOffset and redMultiplier properties in the sample above. Here's how to properly create such a class:

  • Always provide a constructor that can be called without any arguments.
  • Override copyFrom — that's necessary for batching.
  • Override createEffect — this method must return the MeshEffect that will do the actual Stage3D rendering.
  • Override updateEffect — this configures the effect created above right before rendering.
  • Override 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:

  • add a static constant called VERTEX_FORMAT to the class and
  • override get vertexFormat and let it return exactly that format.

When that's done, you can turn to the implementation of your MeshEffect; the createEffect-override will return an instance of this class. Directly before rendering begins, Starling will then call updateEffect to set it up.

@see starling.rendering.MeshEffect @see starling.rendering.VertexDataFormat @see starling.display.Mesh

Hierarchy

Index

Constructors

constructor

Properties

color

color: number

Changes the color of all vertices to the same value. The getter simply returns the color of the first vertex.

indexData

indexData: IndexData

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.

target

target: Mesh

The target the style is currently assigned to.

texture

texture: Texture

The texture that is mapped to the mesh (or null, if there is none).

textureRepeat

textureRepeat: boolean

Indicates if pixels at the edges will be repeated or clamped. Only works for power-of-two textures. @default false

textureSmoothing

textureSmoothing: string

The smoothing filter that is used for the texture. @default bilinear

type

type: any

The actual class of this style.

vertexData

vertexData: VertexData

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.

vertexFormat

vertexFormat: VertexDataFormat

The format used to store the vertices.

Static VERTEX_FORMAT

VERTEX_FORMAT: VertexDataFormat

The vertex format expected by this style (the same as found in the MeshEffect-class).

Methods

addEventListener

  • addEventListener(type: string, listener: Function): void

batchIndexData

  • batchIndexData(targetStyle: MeshStyle, targetIndexID?: number, offset?: number, indexID?: number, numIndices?: number): void
  • 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.

    Parameters

    • targetStyle: MeshStyle
    • Optional targetIndexID: number
    • Optional offset: number
    • Optional indexID: number
    • Optional numIndices: number

    Returns void

batchVertexData

  • batchVertexData(targetStyle: MeshStyle, targetVertexID?: number, matrix?: Matrix, vertexID?: number, numVertices?: number): void
  • 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.

    Parameters

    • targetStyle: MeshStyle
    • Optional targetVertexID: number
    • Optional matrix: Matrix
    • Optional vertexID: number
    • Optional numVertices: number

    Returns void

canBatchWith

  • canBatchWith(meshStyle: MeshStyle): boolean
  • 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.

    Parameters

    Returns boolean

clone

copyFrom

  • 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!

    Parameters

    Returns void

createEffect

dispatchEvent

  • dispatchEvent(event: Event): void
  • 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.

    Parameters

    Returns void

dispatchEventWith

  • dispatchEventWith(type: string, bubbles?: boolean, data?: any): void

getTexCoords

  • getTexCoords(vertexID: number, out?: Point): Point

getVertexAlpha

  • getVertexAlpha(vertexID: number): number

getVertexColor

  • getVertexColor(vertexID: number): number

getVertexPosition

  • getVertexPosition(vertexID: number, out?: Point): Point
  • 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.

    Parameters

    • vertexID: number
    • Optional out: Point

    Returns Point

Protected get_color

  • get_color(): number

Protected get_indexData

Protected get_target

  • get_target(): Mesh

Protected get_texture

Protected get_textureRepeat

  • get_textureRepeat(): boolean

Protected get_textureSmoothing

  • get_textureSmoothing(): string

Protected get_type

  • get_type(): any

Protected get_vertexData

Protected get_vertexFormat

hasEventListener

  • hasEventListener(type: string, listener?: any): boolean

removeEventListener

  • removeEventListener(type: string, listener: Function): void

removeEventListeners

  • removeEventListeners(type?: string): void

setTexCoords

  • setTexCoords(vertexID: number, u: number, v: number): void
  • Sets the texture coordinates of the vertex at the specified index to the given values.

    Parameters

    • vertexID: number
    • u: number
    • v: number

    Returns void

setVertexAlpha

  • setVertexAlpha(vertexID: number, alpha: number): void

setVertexColor

  • setVertexColor(vertexID: number, color: number): void

setVertexPosition

  • setVertexPosition(vertexID: number, x: number, y: number): void

Protected set_color

  • set_color(value: number): number

Protected set_texture

Protected set_textureRepeat

  • set_textureRepeat(value: boolean): boolean

Protected set_textureSmoothing

  • set_textureSmoothing(value: string): string

updateEffect

Generated using TypeDoc