Show another sprite instance

Is it possible to show another instance of the sprite? What I'm trying to do is a reflection of an animated sprite.
What I have so far is my Sprite, called a "canvas", in which there are things that animate inside using AS3. And what I want to do is to show that a copy of it turned upside down, under it, to look like a reflection. I tried the following code but no luck, is it just hiding everything? ..

addChild(canvas);
var reflection:Sprite = new Sprite();
addChild(reflection);
reflection.addChild(canvas);

Any ideas why this code is not working? Or you have a better way to approach this.
Thanks

+3
source share
2 answers

You can use BitmapDatafor this.

class members:

// flip vertically and shift by 100 (insert your canvas size)
private var reflect:Matrix = new Matrix(1, 0, 0, -1, 0, 100);
// instanciate BitmapData with 100x100 size (insert your canvas size),
// filled with black but with 100% transparancy, it an
// ARGB value (0 == 0x00000000)
private var reflectionData:BitmapData = new BitmapData(100, 100, true, 0);
private var reflection:Bitmap = new Bitmap(reflectionData);

INIT:

// you might want to draw canvas already on startup
reflectionData.draw(canvas, reflect);
reflection.x = canvas.x;
reflection.y = canvas.y + canvas.height;
addChild(reflection);

in animation / redrawing

// clear to transparency
reflectionData.fillRect(reflectionData.rect, 0);
// draw the current canvas with matrix applied
reflectionData.draw(canvas, reflect);
+3

, :

?

, .

, , , . , Matrix, Bitmap.draw . , 1 -1. :

http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html

, , , . , , , ( ).

+1

All Articles