To test some image-loading code I wrote in AS3 using the traditional display hierarchy, I would ensure that pixel colors were the right values.

Now I've started to port that code over to Starling, I've noticed that Textures don't have an easy way to get pixel values. This is unfortunate, because it means I'd have to toss a lot of good tests.

Is there any possible way I could do this? Like, could I convert a Texture to BitmapData somehow? Or do you guys have any other suggestions for how to test to ensure that I've properly loaded an image?

1 Answer
1

In fact, this is possible in a limited subset of cases (but the ones that I needed!). The following code is Haxe, but hopefully anyone coming from an AS3 background should be able to translate it with minimal difficulty.

What this code does is render every object that's being displayed in a 3D context to the result BitmapData. Then, we grab a pixel from that BitmapData at the location where the sprite is.

This isn't perfect - it doesn't consider things like rotations, scales, etc. It also doesn't consider if sprite does not have the highest depth. However it is helpful for testing, and it might also come in handy if you need to take a screenshot of the current state of the app/game.