Packagestarling.display
Classpublic class Mesh
InheritanceMesh Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object
Subclasses MeshBatch, Quad

The base class for all tangible (non-container) display objects, spawned up by a number of triangles.

Since Starling uses Stage3D for rendering, all rendered objects must be constructed from triangles. A mesh stores the information of its triangles through VertexData and IndexData structures. The default format stores position, color and texture coordinates for each vertex.

How a mesh is rendered depends on its style. Per default, this is an instance of the MeshStyle base class; however, subclasses may extend its behavior to add support for color transformations, normal mapping, etc.

See also

MeshBatch
starling.styles.MeshStyle
starling.rendering.VertexData
starling.rendering.IndexData


Public Properties
 PropertyDefined By
 Inheritedalpha : Number
The opacity of the object.
DisplayObject
 Inheritedbase : DisplayObject
[read-only] The topmost object in the display tree the object is part of.
DisplayObject
 InheritedblendMode : String
The blend mode determines how the object is blended with the objects underneath.
DisplayObject
 Inheritedbounds : Rectangle
[read-only] The bounds of the object relative to the local coordinates of the parent.
DisplayObject
  color : uint
Changes the color of all vertices to the same value.
Mesh
  defaultStyle : Class
[static] The default style used for meshes if no specific style is provided.
Mesh
 Inheritedfilter : FragmentFilter
The filter that is attached to the display object.
DisplayObject
 Inheritedheight : Number
The height of the object in pixels.
DisplayObject
 Inheritedis3D : Boolean
[read-only] Indicates if this object or any of its parents is a 'Sprite3D' object.
DisplayObject
 Inheritedmask : DisplayObject
The display object that acts as a mask for the current object.
DisplayObject
 Inheritedname : String
The name of the display object (default: null).
DisplayObject
  numIndices : int
[read-only] The total number of indices referencing vertices.
Mesh
  numTriangles : int
[read-only] The total number of triangles in this mesh.
Mesh
  numVertices : int
[read-only] The total number of vertices in the mesh.
Mesh
 Inheritedparent : DisplayObjectContainer
[read-only] The display object container that contains this display object.
DisplayObject
 InheritedpivotX : Number
The x coordinate of the object's origin in its own coordinate space (default: 0).
DisplayObject
 InheritedpivotY : Number
The y coordinate of the object's origin in its own coordinate space (default: 0).
DisplayObject
  pixelSnapping : Boolean
Controls whether or not the instance snaps to the nearest pixel.
Mesh
 InheritedrequiresRedraw : Boolean
[read-only] Indicates if the object needs to be redrawn in the upcoming frame, i.e.
DisplayObject
 Inheritedroot : DisplayObject
[read-only] The root object the display object is connected to (i.e.
DisplayObject
 Inheritedrotation : Number
The rotation of the object in radians.
DisplayObject
 Inheritedscale : Number
Sets both 'scaleX' and 'scaleY' to the same value.
DisplayObject
 InheritedscaleX : Number
The horizontal scale factor.
DisplayObject
 InheritedscaleY : Number
The vertical scale factor.
DisplayObject
 InheritedskewX : Number
The horizontal skew angle in radians.
DisplayObject
 InheritedskewY : Number
The vertical skew angle in radians.
DisplayObject
 Inheritedstage : Stage
[read-only] The stage the display object is connected to, or null if it is not connected to the stage.
DisplayObject
  style : MeshStyle
The style that is used to render the mesh.
Mesh
  texture : Texture
The texture that is mapped to the mesh (or null, if there is none).
Mesh
  textureRepeat : Boolean
Indicates if pixels at the edges will be repeated or clamped.
Mesh
  textureSmoothing : String
The smoothing filter that is used for the texture.
Mesh
 Inheritedtouchable : Boolean
Indicates if this object (and its children) will receive touch events.
DisplayObject
 InheritedtransformationMatrix : Matrix
The transformation matrix of the object relative to its parent.
DisplayObject
 InheritedtransformationMatrix3D : Matrix3D
[read-only] The 3D transformation matrix of the object relative to its parent.
DisplayObject
 InheriteduseHandCursor : Boolean
Indicates if the mouse cursor should transform into a hand while it's over the sprite.
DisplayObject
  vertexFormat : VertexDataFormat
[read-only] The format used to store the vertices.
Mesh
 Inheritedvisible : Boolean
The visibility of the object.
DisplayObject
 Inheritedwidth : Number
The width of the object in pixels.
DisplayObject
 Inheritedx : Number
The x coordinate of the object relative to the local coordinates of the parent.
DisplayObject
 Inheritedy : Number
The y coordinate of the object relative to the local coordinates of the parent.
DisplayObject
Protected Properties
 PropertyDefined By
  indexData : IndexData
[read-only] The index data describing how the vertices are interconnected.
Mesh
  vertexData : VertexData
[read-only] The vertex data describing all vertices of the mesh.
Mesh
Public Methods
 MethodDefined By
  
Mesh(vertexData:VertexData, indexData:IndexData, style:MeshStyle = null)
Creates a new mesh with the given vertices and indices.
Mesh
 Inherited
addEventListener(type:String, listener:Function):void
[override] Registers an event listener at a certain object.
DisplayObject
 Inherited
alignPivot(horizontalAlign:String = center, verticalAlign:String = center):void
Moves the pivot point to a certain position within the local coordinate system of the object.
DisplayObject
 Inherited
dispatchEvent(event:Event):void
Dispatches an event to all objects that have registered listeners for its type.
EventDispatcher
 Inherited
dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void
Dispatches an event with the given parameters to all objects that have registered listeners for the given type.
EventDispatcher
  
dispose():void
[override] Disposes all resources of the display object.
Mesh
  
getBounds(targetSpace:DisplayObject, out:Rectangle = null):Rectangle
[override] Returns a rectangle that completely encloses the object as it appears in another coordinate system.
Mesh
  
getTexCoords(vertexID:int, out:Point = null):Point
Returns the texture coordinates of the vertex at the specified index.
Mesh
 Inherited
getTransformationMatrix(targetSpace:DisplayObject, out:Matrix = null):Matrix
Creates a matrix that represents the transformation from the local coordinate system to another.
DisplayObject
 Inherited
getTransformationMatrix3D(targetSpace:DisplayObject, out:Matrix3D = null):Matrix3D
Creates a matrix that represents the transformation from the local coordinate system to another.
DisplayObject
  
getVertexAlpha(vertexID:int):Number
Returns the alpha value of the vertex at the specified index.
Mesh
  
getVertexColor(vertexID:int):uint
Returns the RGB color of the vertex at the specified index.
Mesh
  
getVertexPosition(vertexID:int, out:Point = null):Point
The position of the vertex at the specified index, in the mesh's local coordinate system.
Mesh
 Inherited
globalToLocal(globalPoint:Point, out:Point = null):Point
Transforms a point from global (stage) coordinates to the local coordinate system.
DisplayObject
 Inherited
globalToLocal3D(globalPoint:Point, out:Vector3D = null):Vector3D
Transforms a point from global (stage) coordinates to the 3D local coordinate system.
DisplayObject
 Inherited
hasEventListener(type:String, listener:Function = null):Boolean
If called with one argument, figures out if there are any listeners registered for the given event type.
EventDispatcher
  
hitTest(localPoint:Point):DisplayObject
[override] Returns the object that is found topmost beneath a point in local coordinates, or nil if the test fails.
Mesh
 Inherited
hitTestMask(localPoint:Point):Boolean
Checks if a certain point is inside the display object's mask.
DisplayObject
 Inherited
local3DToGlobal(localPoint:Vector3D, out:Point = null):Point
Transforms a 3D point from the local coordinate system to global (stage) coordinates.
DisplayObject
 Inherited
localToGlobal(localPoint:Point, out:Point = null):Point
Transforms a point from the local coordinate system to global (stage) coordinates.
DisplayObject
 Inherited
removeEventListener(type:String, listener:Function):void
[override] Removes an event listener from the object.
DisplayObject
 Inherited
removeEventListeners(type:String = null):void
[override] Removes all event listeners with a certain type, or all of them if type is null.
DisplayObject
 Inherited
removeFromParent(dispose:Boolean = false):void
Removes the object from its parent, if it has one, and optionally disposes it.
DisplayObject
  
render(painter:Painter):void
[override] Renders the display object with the help of a painter object.
Mesh
 Inherited
Forces the object to be redrawn in the next frame.
DisplayObject
  
setStyle(meshStyle:MeshStyle = null, mergeWithPredecessor:Boolean = true):void
Sets the style that is used to render the mesh.
Mesh
  
setTexCoords(vertexID:int, u:Number, v:Number):void
Sets the texture coordinates of the vertex at the specified index to the given values.
Mesh
  
setVertexAlpha(vertexID:int, alpha:Number):void
Sets the alpha value of the vertex at the specified index to a certain value.
Mesh
  
setVertexColor(vertexID:int, color:uint):void
Sets the RGB color of the vertex at the specified index to a certain value.
Mesh
  
setVertexPosition(vertexID:int, x:Number, y:Number):void
Mesh
Events
 Event Summary Defined By
 InheritedDispatched when an object is added to a parent.DisplayObject
 InheritedDispatched when an object is connected to the stage (directly or indirectly).DisplayObject
 InheritedDispatched once every frame on every object that is connected to the stage.DisplayObject
 InheritedDispatched when a key on the keyboard is pressed.DisplayObject
 InheritedDispatched when a key on the keyboard is released.DisplayObject
 InheritedDispatched when an object is removed from its parent.DisplayObject
 InheritedDispatched when an object is removed from the stage and won't be rendered any longer.DisplayObject
 InheritedDispatched when an object is touched.DisplayObject
Property Detail
colorproperty
color:uint

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


Implementation
    public function get color():uint
    public function set color(value:uint):void
defaultStyleproperty 
defaultStyle:Class

The default style used for meshes if no specific style is provided. The default is starling.rendering.MeshStyle, and any assigned class must be a subclass of the same.


Implementation
    public static function get defaultStyle():Class
    public static function set defaultStyle(value:Class):void
indexDataproperty 
indexData:IndexData  [read-only]

The index data describing how the vertices are interconnected. Any change requires a call to setRequiresRedraw.


Implementation
    protected function get indexData():IndexData
numIndicesproperty 
numIndices:int  [read-only]

The total number of indices referencing vertices.


Implementation
    public function get numIndices():int
numTrianglesproperty 
numTriangles:int  [read-only]

The total number of triangles in this mesh. (In other words: the number of indices divided by three.)


Implementation
    public function get numTriangles():int
numVerticesproperty 
numVertices:int  [read-only]

The total number of vertices in the mesh.


Implementation
    public function get numVertices():int
pixelSnappingproperty 
pixelSnapping:Boolean

Controls whether or not the instance snaps to the nearest pixel. This can prevent the object from looking blurry when it's not exactly aligned with the pixels of the screen.

The default value is false.


Implementation
    public function get pixelSnapping():Boolean
    public function set pixelSnapping(value:Boolean):void
styleproperty 
style:MeshStyle

The style that is used to render the mesh. Styles (which are always subclasses of MeshStyle) provide a means to completely modify the way a mesh is rendered. For example, they may add support for color transformations or normal mapping.

The setter will simply forward the assignee to setStyle(value).

The default value is MeshStyle.


Implementation
    public function get style():MeshStyle
    public function set style(value:MeshStyle):void
textureproperty 
texture:Texture

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


Implementation
    public function get texture():Texture
    public function set texture(value:Texture):void
textureRepeatproperty 
textureRepeat:Boolean

Indicates if pixels at the edges will be repeated or clamped. Only works for power-of-two textures; for a solution that works with all kinds of textures, see Image.tileGrid.

The default value is false.


Implementation
    public function get textureRepeat():Boolean
    public function set textureRepeat(value:Boolean):void
textureSmoothingproperty 
textureSmoothing:String

The smoothing filter that is used for the texture.

The default value is bilinear.


Implementation
    public function get textureSmoothing():String
    public function set textureSmoothing(value:String):void
vertexDataproperty 
vertexData:VertexData  [read-only]

The vertex data describing all vertices of the mesh. Any change requires a call to setRequiresRedraw.


Implementation
    protected function get vertexData():VertexData
vertexFormatproperty 
vertexFormat:VertexDataFormat  [read-only]

The format used to store the vertices.


Implementation
    public function get vertexFormat():VertexDataFormat
Constructor Detail
Mesh()Constructor
public function Mesh(vertexData:VertexData, indexData:IndexData, style:MeshStyle = null)

Creates a new mesh with the given vertices and indices. If you don't pass a style, an instance of MeshStyle will be created for you. Note that the format of the vertex data will be matched to the given style right away.

Parameters
vertexData:VertexData
 
indexData:IndexData
 
style:MeshStyle (default = null)
Method Detail
dispose()method
override public function dispose():void

Disposes all resources of the display object. GPU buffers are released, event listeners are removed, filters and masks are disposed.

getBounds()method 
override public function getBounds(targetSpace:DisplayObject, out:Rectangle = null):Rectangle

Returns a rectangle that completely encloses the object as it appears in another coordinate system. If you pass an out-rectangle, the result will be stored in this rectangle instead of creating a new object.

Parameters

targetSpace:DisplayObject
 
out:Rectangle (default = null)

Returns
Rectangle
getTexCoords()method 
public function getTexCoords(vertexID:int, out:Point = null):Point

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

Parameters

vertexID:int
 
out:Point (default = null)

Returns
Point
getVertexAlpha()method 
public function getVertexAlpha(vertexID:int):Number

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

Parameters

vertexID:int

Returns
Number
getVertexColor()method 
public function getVertexColor(vertexID:int):uint

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

Parameters

vertexID:int

Returns
uint
getVertexPosition()method 
public function getVertexPosition(vertexID:int, out:Point = null):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:int
 
out:Point (default = null)

Returns
Point
hitTest()method 
override public function hitTest(localPoint:Point):DisplayObject

Returns the object that is found topmost beneath a point in local coordinates, or nil if the test fails. Untouchable and invisible objects will cause the test to fail.

Parameters

localPoint:Point

Returns
DisplayObject
render()method 
override public function render(painter:Painter):void

Renders the display object with the help of a painter object. Never call this method directly, except from within another render method.

Parameters

painter:Painter — Captures the current render state and provides utility functions for rendering.

setStyle()method 
public function setStyle(meshStyle:MeshStyle = null, mergeWithPredecessor:Boolean = true):void

Sets the style that is used to render the mesh. Styles (which are always subclasses of MeshStyle) provide a means to completely modify the way a mesh is rendered. For example, they may add support for color transformations or normal mapping.

When assigning a new style, the vertex format will be changed to fit it. Do not use the same style instance on multiple objects! Instead, make use of style.clone() to assign an identical style to multiple meshes.

Parameters

meshStyle:MeshStyle (default = null) — the style to assign. If null, an instance of a standard MeshStyle will be created.
 
mergeWithPredecessor:Boolean (default = true) — if enabled, all attributes of the previous style will be be copied to the new one, if possible.

setTexCoords()method 
public function setTexCoords(vertexID:int, u:Number, v:Number):void

Sets the texture coordinates of the vertex at the specified index to the given values.

Parameters

vertexID:int
 
u:Number
 
v:Number

setVertexAlpha()method 
public function setVertexAlpha(vertexID:int, alpha:Number):void

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

Parameters

vertexID:int
 
alpha:Number

setVertexColor()method 
public function setVertexColor(vertexID:int, color:uint):void

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

Parameters

vertexID:int
 
color:uint

setVertexPosition()method 
public function setVertexPosition(vertexID:int, x:Number, y:Number):void

Parameters

vertexID:int
 
x:Number
 
y:Number