An active batched tile renderer.
Compared to TileGroup
which is expected to be used as a static geometry,
SpriteBatch uploads GPU buffer each frame by collecting data from added BatchElement
instance.
Due to that, dynamically removing and adding new geometry is fairly simple.
Usage note: While SpriteBatch allows for multiple unique textures, each texture swap causes a new drawcall, and due to that it's recommended to minimize the amount of used textures per SpriteBatch instance, ideally limiting to only one texture.
Constructor
new(t:Tile, ?parent:Object)
Create new SpriteBatch instance.
Parameters:
t | The Tile used as a base Texture to draw contents with. |
---|---|
parent | An optional parent |
Variables
hasRotationScale:Bool = false
Enables usage of rotation and scaling of SpriteBatch elements at the cost of extra calculus.
Makes use of BatchElement.scaleX
, BatchElement.scaleY
and BatchElement.rotation
.
Methods
add(e:BatchElement, before:Bool = false):BatchElement
Adds a new BatchElement to the SpriteBatch.
Parameters:
e | The element to add. |
---|---|
before | When set, element will be added to the beginning of the element chain (rendered first). |
alloc(t:Tile):BatchElement
Creates a new BatchElement and returns it. Shortcut to add(new BatchElement(t))
Parameters:
t | The Tile element will render. |
---|
clear():Void
Removes all elements from the SpriteBatch.
Usage note: Does not clear the BatchElement.batch
nor next
/prev
variables on the child elements.
inlinegetElements():ElementsIterator
Returns an Iterator of all SpriteBatch elements.
Adding or removing the elements will affect the Iterator results.