Unable to use Tilesheet.TILE_ALPHA and Tilesheet.TILE_RGB on Flash target

I am trying to learn how to use OpenFL’s Tilesheet. So far, I am able to render images using the TILE_TRANS_2X2 flag, so I have scaling and rotation covered. However, when I try to use the TILE_ALPHA or TILE_RGB flags, they seem to have no effect on my tiles.

The problem persists on OpenFL 2.1.6, 2.1.7 and 2.2.1 along with Lime 2.0.1 and 2.0.4. I am able to display sprites using HaxeFlixel using these versions, however, so there must be something wrong with my usage of Tilesheet.

Are there any additional setup code or settings I need in order to enable TILE_ALPHA or TILE_RGB? Here is the code I am using at the moment (just with TILE_ALPHA):

var sprite = new Sprite();
addChild(sprite);

var bitmapData = Assets.getBitmapData("assets/img/troll.png");

var tilesheet = new Tilesheet(bitmapData);
tilesheet.addTileRect(new Rectangle(0, 0, 29, 29));

var data:Array<Float> = [
    // x, y, tileID, alpha
    // Tile 1
    1, 1, 0, 1
    // Tile 2
    31, 1, 0, 0.5
    // Tile 3
    61, 1, 0, 0.25
];

tilesheet.drawTiles(sprite.graphics, data, false, Tilesheet.TILE_ALPHA);

As you can see, I am only trying to render three tiles with varying alpha values, and yet I see no difference in the output. This is what I get:

Is there something missing from my code, or am I doing something wrong? Is there any setting I need in the project XML file to make sure TILE_ALPHA and TILE_RGB will work?

UPDATE 1:

It appears that TILE_ALPHA only fails to work on Flash. I built my project for Windows, HTML5 and Android, and in all cases TILE_ALPHA worked as expected.

Here is the result on Windows:

Is Tilesheet hobbled on Flash or something?

UPDATE 2:

I did some more tests and here are the results:

  • Windows and Android - TILE_ROTATION, TILE_SCALE, TILE_RGB, TILE_ALPHA all seem to work
  • HTML5 - TILE_COLOR does not work, while TILE_ROTATION, TILE_SCALE and TILE_ALPHA seem to work.
  • Flash - TILE_COLOR and TILE_ALPHA do not work. TILE_ROTATION behaves differently from other platforms.

Should I steer clear of Tilesheet when in need of cross-platform rendering?

Try tilelayer. It provides the performance of Tilesheet on C++ targets, and it has a fallback for Flash and Neko. (Not sure about HTML5, but if Tilesheet works, tilelayer should too.)

1 Like

It looks like Tilelayer hasn’t been touched in a while, but I’ll give it a whirl. Thanks.

We had no Tilesheet for Flash for a long time, then we added it for compatibility – it does not perform as well on Flash (copyPixels performs better) but it should be consistent. Thanks for bringing this up, we should definitely do the little tweaks necessary to fix this :slight_smile:

I can’t get TILE_ALPHA to work on html5 either (that is, as well as it not working in flash) - kinda saddened to have spent so much time moving over to spritesheets if i’m going to have to rewrite again for flash and html5…

Hmm, should work for HTML5, but if you could share a sample of what you’re trying to do, I can take a look. On HTML5, drawTiles should perform similarly to “new Bitmap”, drawRect and other rendering methods, as they boil down to similar draw calls in canvas either way (though drawTiles will perform faster in WebGL)

TILE_ALPHA was working in html5, found it was my error (drawtiles was overwriting itself, without clearing graphics) - still not in flash though. Think it best i go back to bitmapdata.copypixels and bitmapdata.draw for flash and html5, as i know how to get that working where the tilesheet doesn’t.