Using beginBitmapFill + drawRect instead of Tileset?

I’ve read up on Tileset and Tiles and have a pretty good idea how they work at the top level.

I was wondering if, for non-Flash targets, using a bitmap/texture atlas + *.graphics.beginBitmapFill + *.graphics.drawRect would offer similar performance and draw call count? Or is this a process that is further optimized by using Tileset?

As long as you have only one bitmap (and I do mean bitmap. Not bitmapdata) you should get good performance.

Keep in mind that every bitmap object will render itself and will not batch with other bitmap objects even if they use the same texture.

That means you sacrifice the goodness of the display list father-child relationships.

The advantages of tiles is having multiple objects that share a texture and batch render and can use the display list concepts of father-child (with tilecontainer being analogue to Sprite and Tiles to Bitmaps)

I think that the idea of selecting a texture and drawing rects (or quads :wink: ) is how flixel does things.

My bad, I actually meant “bitmapData”, not “bitmap”. The bitmapData would act as the texture atlas and would be I pass to *.graphics.beginBitmapFill.

hmmm, what I said still stands.

Let’s say I have an atlas in a single .png file and I load said file in a BitmapData object.
Now, I create a Sprite called “bob” and do a bob.graphics.beginBitmapFill and then a bob.graphics.drawRect.

Ok, that is boring, I need another thing on screen. Let’s say I create another Sprite called sally and do the same thing, sally.graphics.beginBitmapFill and sally.graphics.drawRect with the exact same BitmapData that I used for bob.

sally and bob will not be batch rendered. They are in 2 different DisplayObject and each DisplayObject will take one draw call minimum.

The way to get performance would be to create a Sprite called “friends” and do something like

friends.graphics.beginBitmapFill(<Matrix data for bob here>);
friends.graphics.drawRect(<where you need to draw bob>);
friends.graphics.beginBitmapFill(<Matrix data for sally here>);
friends.graphics.drawRect(<where you need to draw sally>);

This is easily achieved if you use graphics.drawQuads https://api.openfl.org/openfl/display/Graphics.html#drawQuads

Ooooh, I see. Thank you for the very detailed answer!

You can take a look on my code. It uses drawTriangles instead of drawQuads. The library is called AtlasTriangle and uses atlas packed with polygon instead of tiles.