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:
- Check all tilemaps. Whenever there is something drawn, copy dark pixels on the darkness layer
- Check all objects, too and also add darkness whenever there is something drawn to the darkness layer
- Check all lightsources. Cut out all areas of light from the darkness layer.
It should be something like this:
![](https://lh3.googleusercontent.com/-yxZUBZUJF-4/VydVPYWKlHI/AAAAAAAAAEI/fbF4twLmfD8c1uO2R5N8umDjizka37oFQCLcB/s320/lighting%2Bidea.jpg)
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