PackagePBLabs.Rendering2D
Classpublic class SpriteSheetComponent
InheritanceSpriteSheetComponent Inheritance EntityComponent

Handles loading and retrieving data about a sprite sheet to use for rendering.

Functionality exists to allow several directions to be specified per frame. This enables you to, for instance, visually rotate a sprite without rotating the actual object it belongs to.

Because we may group them in different ways, we distinguish between "raw frames" and a "frame" which might be made up of multiple directions.

On the subject of sprite sheet order: the divider may alter this, but in general, frames are numbered left to right, top to bottom. If you have a 4 direction sprite sheet, then 0,1,2,3 will be frame 1, 4,5,6,7 will be 2, and so on.

Be aware that Flash implements an upper limit on image size - going over 2048 pixels in any dimension will lead to problems.



Public Properties
 PropertyDefined by
  Center : Point
Specifies an offset so the sprite is centered correctly.
SpriteSheetComponent
  DegreesPerDirection : Number
[read-only] The number of degrees separating each direction.
SpriteSheetComponent
  DirectionsPerFrame : Number = 1
The number of directions per frame.
SpriteSheetComponent
  Divider : ISpriteSheetDivider
The divider to use to chop up the sprite sheet into frames.
SpriteSheetComponent
  FrameCount : int
[read-only] The number of frames the sprite sheet has.
SpriteSheetComponent
  Image : ImageResource
The image resource to use for this sprite sheet.
SpriteSheetComponent
  ImageData : BitmapData
[read-only] The bitmap data of the loaded image.
SpriteSheetComponent
  ImageFilename : String
The filename of the image to use for this sprite sheet.
SpriteSheetComponent
  IsLoaded : Boolean
[read-only] True if the image data associated with this sprite sheet has been loaded.
SpriteSheetComponent
 InheritedIsRegistered : Boolean
Whether or not the component is currently registered with an entity.
EntityComponent
 InheritedName : String
The name given to the component when it is added to an entity.
EntityComponent
 InheritedOwner : IEntity
A reference to the entity that this component currently belongs to.
EntityComponent
  RawFrameCount : int
[read-only] The total number of frames the sprite sheet has.
SpriteSheetComponent
Public Methods
 MethodDefined by
  
GetFrame(index:int, direction:Number = 0.0):BitmapData
Gets the bitmap data for a frame at the specified index.
SpriteSheetComponent
 Inherited
Register(owner:IEntity, name:String):void
Registers the component with an entity.
EntityComponent
 Inherited
Reset():void
This is called by an entity on all of its components any time a component is added or removed.
EntityComponent
 Inherited
Unregister():void
Unregisters the component from an entity.
EntityComponent
Protected Methods
 MethodDefined by
  
_BuildFrames():void
SpriteSheetComponent
  
_GetRawFrame(index:int):BitmapData
Gets the frame at the specified index.
SpriteSheetComponent
 Inherited
_OnAdd():void
This is called when the component is added to an entity.
EntityComponent
  
SpriteSheetComponent
  
SpriteSheetComponent
 Inherited
_OnRemove():void
This is called when the component is removed from an entity.
EntityComponent
 Inherited
_OnReset():void
This is called anytime a component is added or removed from the owner entity.
EntityComponent
Property detail
Centerproperty
Center:Point  [read-write]

Specifies an offset so the sprite is centered correctly. If it is not set, the sprite is centered.

Implementation
    public function get Center():Point
    public function set Center(value:Point):void
DegreesPerDirectionproperty 
DegreesPerDirection:Number  [read-only]

The number of degrees separating each direction.

Implementation
    public function get DegreesPerDirection():Number
DirectionsPerFrameproperty 
public var DirectionsPerFrame:Number = 1

The number of directions per frame.

Dividerproperty 
Divider:ISpriteSheetDivider  [read-write]

The divider to use to chop up the sprite sheet into frames. If the divider isn't set, the image will be treated as one whole frame.

Implementation
    public function get Divider():ISpriteSheetDivider
    public function set Divider(value:ISpriteSheetDivider):void
FrameCountproperty 
FrameCount:int  [read-only]

The number of frames the sprite sheet has. This counts each set of directions as one frame.

Implementation
    public function get FrameCount():int
Imageproperty 
Image:ImageResource  [read-write]

The image resource to use for this sprite sheet.

Implementation
    public function get Image():ImageResource
    public function set Image(value:ImageResource):void
ImageDataproperty 
ImageData:BitmapData  [read-only]

The bitmap data of the loaded image.

Implementation
    public function get ImageData():BitmapData
ImageFilenameproperty 
ImageFilename:String  [read-write]

The filename of the image to use for this sprite sheet.

Implementation
    public function get ImageFilename():String
    public function set ImageFilename(value:String):void
IsLoadedproperty 
IsLoaded:Boolean  [read-only]

True if the image data associated with this sprite sheet has been loaded.

Implementation
    public function get IsLoaded():Boolean
RawFrameCountproperty 
RawFrameCount:int  [read-only]

The total number of frames the sprite sheet has. This counts each direction separately.

Implementation
    public function get RawFrameCount():int
Method detail
_BuildFrames()method
protected function _BuildFrames():void
_GetRawFrame()method 
protected function _GetRawFrame(index:int):BitmapData

Gets the frame at the specified index. This does not take direction into account.

Parameters
index:int

Returns
BitmapData
_OnImageFailed()method 
protected function _OnImageFailed(resource:ImageResource):voidParameters
resource:ImageResource
_OnImageLoaded()method 
protected function _OnImageLoaded(resource:ImageResource):voidParameters
resource:ImageResource
GetFrame()method 
public function GetFrame(index:int, direction:Number = 0.0):BitmapData

Gets the bitmap data for a frame at the specified index.

Parameters
index:int — The index of the frame to retrieve.
 
direction:Number (default = 0.0) — The direction of the frame to retrieve in degrees. This can be ignored if there is only 1 direction per frame.

Returns
BitmapData — The bitmap data for the specified frame, or null if it doesn't exist.