# Sprite

Inheritance Sprite View Module hilo/view/Sprite Requires hilo/core/Hilo, hilo/core/Class, hilo/view/View, hilo/view/Drawable Source Sprite.js
Sprite animation class.

### Properties

Show Inherited Properties

| Property | Defined
--- | --- | ---
| currentFrame:number Current showing frame index, range from 0, readoly! | Sprite
| interval:number Interval between sprite animation frames. | Sprite
| loop:boolean Is sprite play in loop, default value is false. | Sprite
| onEnterFrame:Function Callback function on when sprite enter a new frame. | Sprite
| paused:boolean Is sprite paused, default value is false. | Sprite
| timeBased:boolean Is sprite animate base on time, default value is false (base on frame). | Sprite
| align:String|Function The alignment of the view, the value must be one of Hilo.align enum. | View
| alpha:Number The opacity of the view, default value is 1. | View
| background:Object The background style to fill the view, can be css color, gradient or pattern of canvas | View
| boundsArea:Array The vertex points of the view, the points are relative to the center point. | View
| depth:Number The z index of the view, readonly! | View
| drawable:Drawable The drawable object of the view. | View
| height:Number The height of the view, default value is 0. | View
| id:String The identifier for the view. | View
| mask:Graphics Sets a mask for the view. | View
| onUpdate:Function This method will call while the view need update(usually caused by ticker update). | View
| parent:Container The parent view of this view, readonly! | View
| pivotX:Number Position of the center point on the x axis of the view, default value is 0. | View
| pivotY:Number Position of the center point on the y axis of the view, default value is 0. | View
| pointerEnabled:Boolean Is the view can receive DOM events, default value is true. | View
| rotation:Number The rotation of the view in angles, default value is 0. | View
| scaleX:Number The x axis scale factor of the view, default value is 1. | View
| scaleY:Number The y axis scale factor of the view, default value is 1. | View
| tint:Number The tint applied to the view，default is 0xFFFFFF.Only support in WebGL mode. | View
| transform:Matrix The transform of the view.If set the transform, x, y, scaleX, scaleY, rotation, pivotX, pivotY will be ignored.default is null. | View
| visible:Boolean The visibility of the view. | View
| width:Number The width of the view, default value is 0. | View
| x:Number The position of the view on the x axis relative to the local coordinates of the parent, default value is 0. | View
| y:Number The position of the view on the y axis relative to the local coordinates of the parent, default value is 0. | View

### Methods

Show Inherited Methods

| Method | Defined
--- | --- | ---
| Sprite(properties) Constructor | Sprite
| addFrame(frame:Object, startIndex:Int):Sprite Add frame into sprite. | Sprite
| getFrame(indexOrName:Object):Object Get the frame of given parameter from sprite. | Sprite
| getFrameIndex(frameValue:Object):Object Get frame index from sprite. | Sprite
| getNumFrames():Uint Return the total amount of sprite animation frames. | Sprite
| goto(indexOrName:Object, pause:Boolean):Sprite Jump to an assigned frame. | Sprite
| play():Sprite Play sprite. | Sprite
| setFrame(frame:Object, index:Int):Sprite Set the frame on the given index. | Sprite
| setFrameCallback(frame:Int|String, callback:Function):Sprite Set a callback on an assigned frame. | Sprite
| stop():Sprite Pause playing sprite. | Sprite
| addTo(container:Container, index:Uint):View Add current view to a Contaner. | View
| fire(type:String, detail:Object):Boolean Send events. | View
| getBounds():Array Get the bounds of the view as a circumscribed rectangle and all vertex points relative to the coordinates of the stage. | View
| getScaledHeight():Number Get the scaled height of the view. | View
| getScaledWidth():Number Get the scaled width of the view. | View
| getStage():Stage Get the stage object of the view. | View
| hitTestObject(object:View, usePolyCollision:Boolean) Determining whether an object is in the circumscribed rectangle of current view. | View
| hitTestPoint(x:Number, y:Number, usePolyCollision:Boolean):Boolean Determining whether a point is in the circumscribed rectangle of current view. | View
| off(type:String, listener:Function):Object Remove one event listener. | View
| on(type:String, listener:Function, once:Boolean):Object Add an event listenser. | View
| removeFromParent():View Remove current view from it's parent container | View
| render(renderer:Renderer, delta:Number) The render method of current view. | View
| toString():String Get a string representing current view. | View

### Property Detail

currentFrame:number
Current showing frame index, range from 0, readoly!
interval:number
Interval between sprite animation frames. If timeBased is true, measured in ms, otherwise, measured in frames.
loop:boolean
Is sprite play in loop, default value is false.
onEnterFrame:Function
Callback function on when sprite enter a new frame. default value is null. Note: this function is obsolete, use addFrameCallback funciton instead.
paused:boolean
Is sprite paused, default value is false.
timeBased:boolean
Is sprite animate base on time, default value is false (base on frame).

### Constructor

Sprite(properties)

parameters
properties — Properties parameters for creating object, include all writable properties of this class, also include:

- frames - Sprite animation frames data object.

### Method Detail

addFrame(frame:Object, startIndex:Int):Sprite
Add frame into sprite.

parameters
frame:Object — Frames to add into.
startIndex:Int — The index to start adding frame, if is not given, add at the end of sprite.

return
  Sprite — Sprite itself.

getFrame(indexOrName:Object):Object
Get the frame of given parameter from sprite.

parameters
indexOrName:Object — The index or name of the frame.

return
  Object — The sprite object.

getFrameIndex(frameValue:Object):Object
Get frame index from sprite.

parameters
frameValue:Object — Index or name of the frame.

return
  Object — Sprite frame object.

getNumFrames():Uint
Return the total amount of sprite animation frames.

return
  Uint — The total amount of frames.

goto(indexOrName:Object, pause:Boolean):Sprite
Jump to an assigned frame.

parameters
indexOrName:Object — Index or name of an frame to jump to.
pause:Boolean — Does pause after jumping to the new index.

return
  Sprite — The Sprite object.

play():Sprite
Play sprite.

return
  Sprite — The Sprite object.

setFrame(frame:Object, index:Int):Sprite
Set the frame on the given index.

parameters
frame:Object — The frame data to set on that index.
index:Int — Index of the frame to set.

return
  Sprite — Sprite itself.

setFrameCallback(frame:Int|String, callback:Function):Sprite
Set a callback on an assigned frame. Every time assigned frame is played, invoke the callback function. If callback is empty, callback function will be removed.

parameters
frame:Int|String — Index or name of the assigned frame.
callback:Function — Callback function.

return
  Sprite — The Sprite object.

stop():Sprite
Pause playing sprite.

return
  Sprite — The Sprite object.