BitmapData wrapper which is used for rendering. It stores info about all frames, generated for specific BitmapData object.

Variables

read onlyassetsClass:Class<BitmapData>

Class name for the BitmapData.

read onlyassetsKey:String

Asset name from openfl.Assets.

read onlyatlasFrames:FlxAtlasFrames

Atlas frames for this graphic. You should fill it yourself with one of FlxAtlasFrames's static methods (like fromTexturePackerJson(), fromTexturePackerXml(), etc).

bitmap:BitmapData

The Cached BitmapData object.

read onlycanBeDumped:Bool

Whether the BitmapData of this graphic object can be dumped for decreased memory usage, but may cause some issues (when you need direct access to pixels of this graphic. If the graphic is dumped then you should call undump() and have total access to pixels.

destroyOnNoUse:Bool

Whether this FlxGraphic should be destroyed object when useCount become zero. Default is true.

read onlyheight:Int = 0

Height of the cached BitmapData.

read onlyimageFrame:FlxImageFrame

FlxImageFrame object for the whole bitmap.

read onlyisDumped:Bool = false

Whether the BitmapData of this graphic object has been dumped or not.

read onlykey:String

Key used in the BitmapFrontEnd cache.

persist:Bool = false

Whether this graphic object should stay in cache after state changes or not.

read onlytilesheet:Tilesheet

Tilesheet for this graphic object. It is used only for FlxG.renderTile mode.

unique:Bool = false

Shows whether this object unique in cache or not.

Whether undumped BitmapData should be cloned or not. It is false by default, since it significantly increases memory consumption.

useCount:Int

Usage counter for this FlxGraphic object.

read onlywidth:Int = 0

Width of the cached BitmapData.

Methods

addFrameCollection(collection:FlxFramesCollection):Void

Stores specified FlxFrame collection in internal map (this helps reduce object creation).

Parameters:

collection

frame collection to store.

destroy():Void

Trying to free the memory as much as possible

dump():Void

Dumps bits of BitmapData to decrease memory usage, but you can't read/write pixels on it anymore (but you can call onContext() (or undump()) method which will restore it again).

inlinegetEmptyFrame(size:FlxPoint):FlxFrame

Creates empty frame for this graphic with specified size. This method could be useful for tile frames, in case when you'll need empty tile.

Parameters:

size

dimensions of the frame to add.

Returns:

Empty frame with specified size which belongs to this FlxGraphic object.

inlinegetFramesCollections(type:FlxFrameCollectionType):Array<Dynamic>

Searches frame collections of specified type for this FlxGraphic object.

Parameters:

type

The type of frames collections to search for.

Returns:

Array of available frames collections of specified type for this object.

onAssetsReload():Void

Asset reload callback for this graphic object. It regenerated its tilesheet and resets frame bitmaps.

onContext():Void

Use this method to restore cached BitmapData (if it's possible). It's called automatically when the RESIZE event occurs.

undump():Void

Undumps bits of the BitmapData - regenerates it and regenerate tilesheet data for this object

Static variables

staticdefaultPersist:Bool = false

The default value for the persist variable at creation if none is specified in the constructor.

Static methods

staticfromAssetKey(Source:String, Unique:Bool = false, ?Key:String, Cache:Bool = true):FlxGraphic

Creates and caches FlxGraphic object from openfl.Assets key string.

Parameters:

Source

openfl.Assets key string. For example: "assets/image.png".

Unique

Ensures that the BitmapData uses a new slot in the cache. If true, then BitmapData for this FlxGraphic will be cloned, which means extra memory.

Key

Force the cache to use a specific key to index the bitmap.

Cache

Whether to use graphic caching or not. Default value is true, which means automatic caching.

Returns:

Cached FlxGraphic object we just created.

staticfromBitmapData(Source:BitmapData, Unique:Bool = false, ?Key:String, Cache:Bool = true):FlxGraphic

Creates and caches FlxGraphic object from specified BitmapData object.

Parameters:

Source

BitmapData for FlxGraphic to use.

Unique

Ensures that the BitmapData uses a new slot in the cache. If true, then BitmapData for this FlxGraphic will be cloned, which means extra memory.

Key

Force the cache to use a specific key to index the bitmap.

Cache

Whether to use graphic caching or not. Default value is true, which means automatic caching.

Returns:

FlxGraphic object we just created.

staticfromClass(Source:Class<BitmapData>, Unique:Bool = false, ?Key:String, Cache:Bool = true):FlxGraphic

Creates and caches FlxGraphic object from a specified Class<BitmapData>.

Parameters:

Source

Class<BitmapData> to create BitmapData for FlxGraphic from.

Unique

Ensures that the BitmapData uses a new slot in the cache. If true, then BitmapData for this FlxGraphic will be cloned, which means extra memory.

Key

Force the cache to use a specific key to index the bitmap.

Cache

Whether to use graphic caching or not. Default value is true, which means automatic caching.

Returns:

FlxGraphic object we just created.

staticfromFrame(Source:FlxFrame, Unique:Bool = false, ?Key:String, Cache:Bool = true):FlxGraphic

Creates and (optionally) caches a FlxGraphic object from the specified FlxFrame. It uses frame's BitmapData, not the frame.parent.bitmap.

Parameters:

Source

FlxFrame to get the BitmapData from.

Unique

Ensures that the bitmap data uses a new slot in the cache. If true, then BitmapData for this FlxGraphic will be cloned, which means extra memory.

Key

Force the cache to use a specific key to index the bitmap.

Cache

Whether to use graphic caching or not. Default value is true, which means automatic caching.

Returns:

FlxGraphic object we just created.

staticinlinefromFrames(Source:FlxFramesCollection, Unique:Bool = false, ?Key:String):FlxGraphic

Creates and caches a FlxGraphic object from the specified FlxFramesCollection. It uses frames.parent.bitmap as a source for the FlxGraphic's BitmapData. It also copies all the frames collections onto the newly created FlxGraphic.

Parameters:

Source

FlxFramesCollection to get the BitmapData from.

Unique

Ensures that the BitmapData uses a new slot in the cache. If true, then BitmapData for this FlxGraphic will be cloned, which means extra memory.

Key

Force the cache to use a specific key to index the bitmap.

Returns:

Cached FlxGraphic object we just created.

staticfromGraphic(Source:FlxGraphic, Unique:Bool = false, ?Key:String):FlxGraphic

Creates and caches a FlxGraphic object from the specified FlxGraphic object. It copies all the frame collections onto the newly created FlxGraphic.

Parameters:

Source

FlxGraphic to get the BitmapData from.

Unique

Ensures that the BitmapData uses a new slot in the cache. If true, then BitmapData for this FlxGraphic will be cloned, which means extra memory.

Key

Force the cache to use a specific key to index the bitmap.

Returns:

Cached FlxGraphic object we just created.

staticfromRectangle(Width:Int, Height:Int, Color:FlxColor, Unique:Bool = false, ?Key:String):FlxGraphic

Generates and caches new FlxGraphic object with a colored rectangle.

Parameters:

Width

How wide the rectangle should be.

Height

How high the rectangle should be.

Color

What color the rectangle should have (0xAARRGGBB).

Unique

Ensures that the BitmapData uses a new slot in the cache.

Key

Force the cache to use a specific key to index the bitmap.

Returns:

The FlxGraphic object we just created.