Internal storage system to prevent graphics from being used repeatedly in memory.

Accessed via FlxG.bitmap.

Constructor

new()

Variables

read onlywhitePixel:FlxFrame

Helper FlxFrame object. Containing only one frame. Useful for drawing colored rectangles of all sizes in FlxG.renderTile mode.

Methods

@:value({ Unique : false })add(Graphic:FlxGraphicAsset, Unique:Bool = false, ?Key:String):FlxGraphic

Loads a bitmap from a file, clones it if necessary and caches it.

Parameters:

Graphic

Optional FlxGraphics object to create FlxGraphic from.

Frames

Optional FlxFramesCollection object to create FlxGraphic from.

Bitmap

Optional BitmapData object to create FlxGraphic from.

BitmapClass

Optional Class for BitmapData to create FlxGraphic from.

Str

Optional String key to use for FlxGraphic instantiation.

Unique

Ensures that the bitmap data uses a new slot in the cache.

Key

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

Returns:

The FlxGraphic we just created.

inlineaddGraphic(graphic:FlxGraphic):FlxGraphic

Caches specified FlxGraphic object.

Parameters:

graphic

FlxGraphic to store in the cache.

Returns:

cached FlxGraphic object.

inlinecheckCache(Key:String):Bool

Check the local bitmap cache to see if a bitmap with this key has been loaded already.

Parameters:

Key

The string key identifying the bitmap.

Returns:

Whether or not this file can be found in the cache.

@:has_untypedclearCache():Void

Clears image cache (and destroys those images). Graphics object will be removed and destroyed only if it shouldn't persist in the cache and its useCount is 0.

@:has_untypedclearUnused():Void

Removes all unused graphics from cache, but skips graphics which should persist in cache and shouldn't be destroyed on no use.

@:value({ Unique : false })create(Width:Int, Height:Int, Color:FlxColor, Unique:Bool = false, ?Key:String):FlxGraphic

Generates a new BitmapData object (a colored rectangle) and caches it.

Parameters:

Width

How wide the rectangle should be.

Height

How high the rectangle should be.

Color

What color the rectangle should be (0xAARRGGBB)

Unique

Ensures that the bitmap data uses a new slot in the cache.

Key

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

Returns:

The BitmapData we just created.

dumpCache():Void

Dumps bits of all graphics in the cache. This frees some memory, but you can't read/write pixels on those graphics anymore. You can call undump() method for each FlxGraphic (or undumpCache()) object which will restore it again.

@:has_untypedfindKeyForBitmap(bmd:BitmapData):String

Gets key from bitmap cache for specified BitmapData

Parameters:

bmd

BitmapData to find in cache

Returns:

BitmapData's key or null if there isn't such BitmapData in cache

@:value({ unique : false })generateKey(systemKey:String, userKey:String, unique:Bool = false):String

Creates string key for further caching.

Parameters:

systemKey

The first string key to use as a base for a new key. It's usually a key from openfl.Assets ("assets/image.png").

userKey

The second string key to use as a base for a new key. It's usually a key provided by the user

unique

Whether generated key should be unique or not.

Returns:

Created key.

inlineget(key:String):FlxGraphic

Gets FlxGraphic object from this storage by specified key.

Parameters:

key

Key for FlxGraphic object (its name)

Returns:

FlxGraphic with the key name, or null if there is no such object

inlinegetKeyForClass(source:Class<Dynamic>):String

Helper method for getting cache key for FlxGraphic objects created from the class.

Parameters:

source

BitmapData source class.

Returns:

Full name for provided class.

getKeyWithSpacesAndBorders(baseKey:String, ?frameSize:FlxPoint, ?frameSpacing:FlxPoint, ?frameBorder:FlxPoint, ?region:FlxRect):String

Generates key from provided base key and information about tile size and offsets in spritesheet and the region of image to use as spritesheet graphics source.

Parameters:

baseKey

Beginning of the key. Usually it is the key for original spritesheet graphics (like "assets/tile.png")

frameSize

the size of tile in spritesheet

frameSpacing

offsets between tiles in offsets

region

region of image to use as spritesheet graphics source

Returns:

Generated key for spritesheet with inserted spaces between tiles

getUniqueKey(?baseKey:String):String

Gets unique key for bitmap cache

Parameters:

baseKey

key's prefix

Returns:

unique key

@:has_untypedonAssetsReload(_:Dynamic):Void

@:has_untypedonContext():Void

New context handler. Regenerates tilesheets for all dumped graphics objects in the cache.

remove(graphic:FlxGraphic):Void

Totally removes specified FlxGraphic object.

Parameters:

FlxGraphic

object you want to remove and destroy.

removeByKey(key:String):Void

Totally removes FlxGraphic object with specified key.

Parameters:

key

the key for cached FlxGraphic object.

@:has_untypedreset():Void

Completely resets bitmap cache, which means destroying ALL of the cached FlxGraphic objects.

undumpCache():Void

Restores graphics of all dumped objects in the cache.