在 Flash 中以编程方式淡出至消失点(当然)

发布于 2024-07-14 02:01:01 字数 533 浏览 7 评论 0 原文

我正在尝试做一个消失的星球大战类型的事情,比如 this ,但是以编程方式。

他们所做的大部分工作都很容易编程(制作补间动画),但我也希望以编程方式生成基于文本的图形(例如,使用动态文本对象从文本生成)。

在我看来,问题(当然,我对其他看待它的方式持开放态度)是:有没有办法从我的动态中获得斜边矩形-文本对象?此处提到了scale9grid< /a> 不会这样做,我很确定。 我想指定四个点来获得菱形(如果这就是它的名字)。

I'm trying to do a vanishing Star Wars type thing like this, but programatically.

Most of what they've done is easy to program (make a motion tween), but I wish to generate the text-based graphic programatically as well (from text using a dynamic text obj, for example).

The question, as I see it (but I'm open to other ways of seeing it, of course) is: is there any way to get a slanty-sided rectangle from my dynamic-text object? The scale9grid mentioned here will not do it, I'm quite sure. I want to specify four points to get a rhombus (if that's what it's called).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你穿错了嫁妆 2024-07-21 02:01:01

如果您正在为 Flash Player 10 进行编译(需要 CS4 或最新的 Flex sdk),则只需在 3D 中旋转文本字段:

text.rotateX = -45;

还有一些问题,例如您需要使用字体嵌入,并获取消失点在视场的中心。

在 Flash Player 中执行此操作 < 10 位图也是可能的,如果你是受虐狂,并且不介意一些垂直锯齿。 这个想法是使用 BitmapData.draw() 绘制具有高度 1 剪切矩形的每条线,并进行变换以进行透视划分。 例如(在弯曲中):

class Main extends Sprite
{
    [Embed(systemFont="Arial", fontName="embedFont", mimeType="application/x-font")]
    var embedFont:Class;

    public function Main()
    {
        var text:TextField = new TextField();
        text.defaultTextFormat = new TextFormat("embedFont", 30);
        text.embedFonts = true;
        text.autoSize = TextFieldAutoSize.LEFT;
        text.text = "Hello, world\nHow nice\nto have\nmultiple\nlines!";
        var bmp:BitmapData = new BitmapData(150, 100);

        for (var i:int = 0; i != bmp.height; ++i) {
            var m:Matrix = new Matrix();
            // x-division, change 0.8, 0.2 to change scale increase, scale at top
            m.a = i*(0.8/bmp.height)+0.2;
            // horizontal center
            m.tx = bmp.width * (1-m.a) / 2;
            // y-division, and align text to bottom
            m.ty = (bmp.height-i)/m.a - bmp.height; 
            bmp.draw(text, m, null, null, new Rectangle(0, i, bmp.width, 1));
        }

        addChild(new Bitmap(bmp));
    }
}

我没有做过数学计算,所以我不知道这在物理上是否准确,但它应该给你一个想法。

If you are compiling for flash player 10 (which requires CS4 or a recent flex sdk), you can just rotate the text field in 3d:

text.rotateX = -45;

There are a few more issues with this, such as you need to use font embedding, and getting the vanishing point in the center of the field.

Doing this in flash player < 10 with bitmaps is also possible, if you are masochistic, and don't mind some vertical aliasing. The idea would be to use BitmapData.draw() to draw each line with a height 1 clipping rect and a transform to do the perspective division. Eg (in flex):

class Main extends Sprite
{
    [Embed(systemFont="Arial", fontName="embedFont", mimeType="application/x-font")]
    var embedFont:Class;

    public function Main()
    {
        var text:TextField = new TextField();
        text.defaultTextFormat = new TextFormat("embedFont", 30);
        text.embedFonts = true;
        text.autoSize = TextFieldAutoSize.LEFT;
        text.text = "Hello, world\nHow nice\nto have\nmultiple\nlines!";
        var bmp:BitmapData = new BitmapData(150, 100);

        for (var i:int = 0; i != bmp.height; ++i) {
            var m:Matrix = new Matrix();
            // x-division, change 0.8, 0.2 to change scale increase, scale at top
            m.a = i*(0.8/bmp.height)+0.2;
            // horizontal center
            m.tx = bmp.width * (1-m.a) / 2;
            // y-division, and align text to bottom
            m.ty = (bmp.height-i)/m.a - bmp.height; 
            bmp.draw(text, m, null, null, new Rectangle(0, i, bmp.width, 1));
        }

        addChild(new Bitmap(bmp));
    }
}

I haven't done the maths, so I don't know if that's physically accurate, but it should give you an idea.

已下线请稍等 2024-07-21 02:01:01

您可能会考虑将文本对象转换为图像,然后对图像执行此操作。

-亚当

You might consider converting the text object to an image, and then doing that to the image.

-Adam

献世佛 2024-07-21 02:01:01

在 Flash Player 9 及更早版本中,您实际上无法以简单的方式执行此操作。
Flash Player 10 和 Flash CS4 引入了对 3D 转换的一些基本支持,但这些支持非常简单,而且我想这种“极端”视角可能很难正确实现。 不过,我没有使用过 CS4 创作工具,所以那里可能更容易。

还有完整的 3D 引擎,例如 papervisionaway3d 尽管它们有点矫枉过正。

我认为最好的可能是使用 DisplacementMapFilter ,我在网上找到任何好的例子时遇到了一些困难,而且我自己从未真正做过,但我认为 文档中的示例应该可以帮助您很好地入门。

如果您愿意,您也可以将所有像素绘制到位图上并逐一处理它们,这可能是编码中最有趣的事情,但它可能会非常慢并且看起来不太好;)

You can't really do this in a simple way in Flash Player 9 and earlier.
Flash player 10 and Flash CS4 introduces some basic support for 3D transformations, but these are quite simple, and i guess this "extreme" perspective could be tricky to get right. I have however not used the CS4 authoring tool, so it might be easier in there.

There are also the full 3D engines like papervision and away3d although they are a bit overkill.

What I think might be best is using a DisplacementMapFilter, I had some trouble finding any good examples of this online, and I've never actually done it myself, but I think the example in the docs should get you started just fine.

If you feel up for it you can also just draw all the pixels to a bitmap and have at them one by one, that might be the most fun thing to code, but it will likely be quite slow and not look as good ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文