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

- EventDispatcher
  - MeshStyle
    - DistanceFieldStyle

## Index

### Constructors

- constructor

### Properties

- color
- indexData
- target
- texture
- textureRepeat
- textureSmoothing
- type
- vertexData
- vertexFormat
- VERTEX_FORMAT

### Methods

- addEventListener
- batchIndexData
- batchVertexData
- canBatchWith
- clone
- copyFrom
- createEffect
- dispatchEvent
- dispatchEventWith
- getTexCoords
- getVertexAlpha
- getVertexColor
- getVertexPosition
- get_color
- get_indexData
- get_target
- get_texture
- get_textureRepeat
- get_textureSmoothing
- get_type
- get_vertexData
- get_vertexFormat
- hasEventListener
- removeEventListener
- removeEventListeners
- setTexCoords
- setVertexAlpha
- setVertexColor
- setVertexPosition
- set_color
- set_texture
- set_textureRepeat
- set_textureSmoothing
- updateEffect

## Constructors

### constructor

- new MeshStyle(): MeshStyle

- Overrides EventDispatcher.constructor

  - Defined in lib/starling/styles/MeshStyle.d.ts:85

  Creates a new MeshStyle instance. Subclasses must provide a constructor that can be called without any arguments.

  #### Returns MeshStyle

## Properties

### color

color: number

- Defined in lib/starling/styles/MeshStyle.d.ts:201

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

### indexData

indexData: IndexData

- Defined in lib/starling/styles/MeshStyle.d.ts:192

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

- Defined in lib/starling/styles/MeshStyle.d.ts:226

The target the style is currently assigned to.

### texture

texture: Texture

- Defined in lib/starling/styles/MeshStyle.d.ts:210

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

### textureRepeat

textureRepeat: boolean

- Defined in lib/starling/styles/MeshStyle.d.ts:221

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

### textureSmoothing

textureSmoothing: string

- Defined in lib/starling/styles/MeshStyle.d.ts:215

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

### type

type: any

- Defined in lib/starling/styles/MeshStyle.d.ts:196

The actual class of this style.

### vertexData

vertexData: VertexData

- Defined in lib/starling/styles/MeshStyle.d.ts:186

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

- Defined in lib/starling/styles/MeshStyle.d.ts:206

The format used to store the vertices.

### Static VERTEX_FORMAT

VERTEX_FORMAT: VertexDataFormat

- Defined in lib/starling/styles/MeshStyle.d.ts:85

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

## Methods

### addEventListener

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

- Overrides EventDispatcher.addEventListener

  - Defined in lib/starling/styles/MeshStyle.d.ts:144

  #### Parameters

  - ##### type: string

  - ##### listener: Function

  #### Returns void

### batchIndexData

- batchIndexData(targetStyle: MeshStyle, targetIndexID?: number, offset?: number, indexID?: number, numIndices?: number): void

- - Defined in lib/starling/styles/MeshStyle.d.ts:139

  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

- - Defined in lib/starling/styles/MeshStyle.d.ts:128

  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

- - Defined in lib/starling/styles/MeshStyle.d.ts:118

  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

  - ##### meshStyle: MeshStyle

  #### Returns boolean

### clone

- clone(): MeshStyle

- - Defined in lib/starling/styles/MeshStyle.d.ts:98

  Creates a clone of this instance. The method will work for subclasses automatically, no need to override it.

  #### Returns MeshStyle

### copyFrom

- copyFrom(meshStyle: MeshStyle): void

- - Defined in lib/starling/styles/MeshStyle.d.ts:94

  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

  - ##### meshStyle: MeshStyle

  #### Returns void

### createEffect

- createEffect(): MeshEffect

- - Defined in lib/starling/styles/MeshStyle.d.ts:103

  Creates the effect that does the actual, low-level rendering. To be overridden by subclasses!

  #### Returns MeshEffect

### dispatchEvent

- dispatchEvent(event: Event): void

- Inherited from EventDispatcher.dispatchEvent

  - Defined in lib/starling/events/EventDispatcher.d.ts:45

  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

  - ##### event: Event

  #### Returns void

### dispatchEventWith

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

- Inherited from EventDispatcher.dispatchEventWith

  - Defined in lib/starling/events/EventDispatcher.d.ts:50

  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.

  #### Parameters

  - ##### type: string

  - ##### Optional bubbles: boolean

  - ##### Optional data: any

  #### Returns void

### getTexCoords

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

- - Defined in lib/starling/styles/MeshStyle.d.ts:176

  Returns the texture coordinates of the vertex at the specified index.

  #### Parameters

  - ##### vertexID: number

  - ##### Optional out: Point

  #### Returns Point

### getVertexAlpha

- getVertexAlpha(vertexID: number): number

- - Defined in lib/starling/styles/MeshStyle.d.ts:164

  Returns the alpha value of the vertex at the specified index.

  #### Parameters

  - ##### vertexID: number

  #### Returns number

### getVertexColor

- getVertexColor(vertexID: number): number

- - Defined in lib/starling/styles/MeshStyle.d.ts:170

  Returns the RGB color of the vertex at the specified index.

  #### Parameters

  - ##### vertexID: number

  #### Returns number

### getVertexPosition

- getVertexPosition(vertexID: number, out?: Point): Point

- - Defined in lib/starling/styles/MeshStyle.d.ts:159

  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

- - Defined in lib/starling/styles/MeshStyle.d.ts:202

  #### Returns number

### Protected get_indexData

- get_indexData(): IndexData

- - Defined in lib/starling/styles/MeshStyle.d.ts:193

  #### Returns IndexData

### Protected get_target

- get_target(): Mesh

- - Defined in lib/starling/styles/MeshStyle.d.ts:227

  #### Returns Mesh

### Protected get_texture

- get_texture(): Texture

- - Defined in lib/starling/styles/MeshStyle.d.ts:211

  #### Returns Texture

### Protected get_textureRepeat

- get_textureRepeat(): boolean

- - Defined in lib/starling/styles/MeshStyle.d.ts:222

  #### Returns boolean

### Protected get_textureSmoothing

- get_textureSmoothing(): string

- - Defined in lib/starling/styles/MeshStyle.d.ts:216

  #### Returns string

### Protected get_type

- get_type(): any

- - Defined in lib/starling/styles/MeshStyle.d.ts:197

  #### Returns any

### Protected get_vertexData

- get_vertexData(): VertexData

- - Defined in lib/starling/styles/MeshStyle.d.ts:187

  #### Returns VertexData

### Protected get_vertexFormat

- get_vertexFormat(): VertexDataFormat

- - Defined in lib/starling/styles/MeshStyle.d.ts:207

  #### Returns VertexDataFormat

### hasEventListener

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

- Inherited from EventDispatcher.hasEventListener

  - Defined in lib/starling/events/EventDispatcher.d.ts:55

  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.

  #### Parameters

  - ##### type: string

  - ##### Optional listener: any

  #### Returns boolean

### removeEventListener

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

- Overrides EventDispatcher.removeEventListener

  - Defined in lib/starling/styles/MeshStyle.d.ts:146

  #### Parameters

  - ##### type: string

  - ##### listener: Function

  #### Returns void

### removeEventListeners

- removeEventListeners(type?: string): void

- Inherited from EventDispatcher.removeEventListeners

  - Defined in lib/starling/events/EventDispatcher.d.ts:39

  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.

  #### Parameters

  - ##### Optional type: string

  #### Returns void

### setTexCoords

- setTexCoords(vertexID: number, u: number, v: number): void

- - Defined in lib/starling/styles/MeshStyle.d.ts:179

  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

- - Defined in lib/starling/styles/MeshStyle.d.ts:167

  Sets the alpha value of the vertex at the specified index to a certain value.

  #### Parameters

  - ##### vertexID: number

  - ##### alpha: number

  #### Returns void

### setVertexColor

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

- - Defined in lib/starling/styles/MeshStyle.d.ts:173

  Sets the RGB color of the vertex at the specified index to a certain value.

  #### Parameters

  - ##### vertexID: number

  - ##### color: number

  #### Returns void

### setVertexPosition

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

- - Defined in lib/starling/styles/MeshStyle.d.ts:161

  #### Parameters

  - ##### vertexID: number

  - ##### x: number

  - ##### y: number

  #### Returns void

### Protected set_color

- set_color(value: number): number

- - Defined in lib/starling/styles/MeshStyle.d.ts:203

  #### Parameters

  - ##### value: number

  #### Returns number

### Protected set_texture

- set_texture(value: Texture): Texture

- - Defined in lib/starling/styles/MeshStyle.d.ts:212

  #### Parameters

  - ##### value: Texture

  #### Returns Texture

### Protected set_textureRepeat

- set_textureRepeat(value: boolean): boolean

- - Defined in lib/starling/styles/MeshStyle.d.ts:223

  #### Parameters

  - ##### value: boolean

  #### Returns boolean

### Protected set_textureSmoothing

- set_textureSmoothing(value: string): string

- - Defined in lib/starling/styles/MeshStyle.d.ts:217

  #### Parameters

  - ##### value: string

  #### Returns string

### updateEffect

- updateEffect(effect: MeshEffect, state: RenderState): void

- - Defined in lib/starling/styles/MeshStyle.d.ts:111

  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!

  #### Parameters

  - ##### effect: MeshEffect

  - ##### state: RenderState

  #### Returns void

Generated using TypeDoc