You’ve seen it everywhere, even in the new iTunes. Basically the idea is to create a reflection of an image, as if the surface it is standing on was mirror-like.
I’ve managed to hack away some code using the BitmapData, Bitmap and Sprite classes. This is probably not an efficient way to do things, especially the changeAlpha function which adapts the negative color values (why do I get that?) for each pixel.
_art is a Sprite containing the image we want to create the reflection of; in my example _art has been scaled by fixing it’s width and height dynamically, therefore we need to take that into consideration when drawing it’s content into a BitmapData object
_artReflection is a Sprite which will contain the reflection
Here we go:
Voilà. Post your comments or questions! Or even better, improve the efficiency of my code!
and thanks for the useful script!
How do you create a Sprite from an image loaded dynamically? Could you post some fast code about that?
link to source if you’d like help with your code, mate.
if you cast as uint you won’t get negative values…
var alphaOffset:uint = color>>> 24 & 0xFF;
var redOffset:uint = color>>> 16 & 0xFF;
var greenOffset:uint = color >>> 8 & 0xFF;
var blueOffset:uint = color & 0xFF;
//i = (x ^ (x >> 31)) – (x >> 31); this is the same as math.abs …also ternary below
thanks again, this is fun to play with…
That’s pretty neat stuff, definitely fun to play with. As you said, probably not the most efficient, but it can be fixed up.
[…] least come with the addition of online leaderboards. … Mail (will not be published) (required) …intense creativity Tutorial – Creating the reflection of an …I’ve managed to hack away some code using the BitmapData, Bitmap and Sprite classes. … _art is a […]