How to access the BitmapData of a FlxTilemap

47 views
Skip to first unread message

sano98

unread,
May 2, 2016, 9:39:17 AM5/2/16
to HaxeFlixel


Again, I'm trying to access the bitmapData of something that is drawn on the screen. This time, it's a FlxTilemap. Where talking about flash-target and flixel dev 4.0.1.

What do I want:
I want to use and manilpulate the bitmapData of a Tilemap. Not the Tilesheet file it is based on, but the resulting thing that gets painted on the screen, after loading the map. If we were talking about a FlxSprite instead of a FlxTilemap, the thing I am looking for would be mySprite.pixels.

What do I need that for:
I want to do some lighting stuff. Therefore, I am using bitmaps in a copyPixels()-operation. I want to use the bitmapData of the FlxTilemap as the alphaBitmapData-Parameter in the operation.

Can I be more specific?:
Of course. My idea for a horizontal building lighting system is making a darkness overlay. But instead of only stamping the light sources out, I only want the darkness layer to be at positions where there actually is an obstacle. Like a wall or an object. Therefore, my plan is:
  1. Check all tilemaps. Whenever there is something drawn, copy dark pixels on the darkness layer
  2. Check all objects, too and also add darkness whenever there is something drawn to the darkness layer
  3. Check all lightsources. Cut out all areas of light from the darkness layer.

It should be something like this:



The darkness layer is like the silhouette of my level; with all walls, objects and characters.




What I have tried so far:


  • The function myTilemap.tileToSprite()seemed like a good idea - just make a sprite out of my tilemap and then smoothly access the bitmapData. Unfortunately, it doesn't seem to transform the resulting tilemap, but only the underlying tilesheet graphic data.
  • Having a close look at the FlxTilemap-function drawTilemap(), as here someting gets actually copied to a FlxTilemapBuffer. But I didn't really grasp what's going on here.
  • Using the FlxTilemapBuffer. Somewhere here, the bitmapData has to be. The private var pixels looked like a good candidate; but again, couldn't get it to work.


According to my understanding, when something is drawn on the screen, at some point in the rendering pipeline, it must exist as a bitmapData. I simply need to find where!



Best,

-sano

sano98

unread,
May 5, 2016, 8:54:38 AM5/5/16
to HaxeFlixel
I think I got it.
  1. Create a new TileMapbuffer with the respective data from your tilemap
  2. Call the function drawTilemap() and hand it your new and empty TilemapBuffer and your standard camera. I think I had to change this function from private to public.
  3. This TilemapBuffer has the attribute pixels, which refers to the current bitmap of your tilemap..
Reply all
Reply to author
Forward
0 new messages