显示一个精灵的另一个实例 [英] Show another instance of a sprite

查看:138
本文介绍了显示一个精灵的另一个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能表现出精灵的另一个实例?我想要做的是有一个动画精灵的反映。
我已经走到这一步,是我的雪碧所谓的画布上,有东西通过使用AS3里面有动画显示。而我想要做的是显示的副本它翻转,低于它看起来像一个反映。我尝试以下code,但没有运气,它只是隐藏一切吗?..

Is it possible to show another instance of a sprite? What I'm trying to do is have a reflection of a animated sprite.
What I've got so far is my Sprite called "canvas" that has things animating inside it by use of AS3. And what I want to do is show a copy of it flipped, below it to look like a reflection. I tried the following code but to no luck, it just hides everything?..

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

任何想法,为什么这code不起作用?或者你有更好的方法来处理这​​个。
谢谢

Any ideas why this code doesn't work? Or do you have a better way to approach this.
Thanks

推荐答案

您可以使用的BitmapData

类成员:

// 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's 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);

在动画/重绘

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

这篇关于显示一个精灵的另一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆