绘制三次Bezier曲线的Actionscript? [英] Draw cubic bezier curves in Actionscript?

查看:262
本文介绍了绘制三次Bezier曲线的Actionscript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是绘制三次Bezier曲线编程在AS3的最佳方法是什么?该图形类似乎只支持二次曲线。 :(我希望能够做一些事情,如:

  VAR的startPoint:点=新的点(0,0);
VAR端点:点=新的点(5,5);
VAR控制1:点=新的点(5,0);
VAR控制2:点=新的点(0,5);

VAR myBezier:雪碧= getBezier(的startPoint,控制1,控制2,终点);
 

有关为服务目标,我打算让〜50这些在舞台上的一次。

解决方案
  

注意:的Flash Player 11日起,包括一个本地方法来绘制三次曲线,<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#cubicCurveTo%28%29"相对=nofollow> cubicCurveTo()这应该是最快的方法,如果你的目标FP11。

就在上周,我写了一个类来绘制任意阶Bezier曲线。

在code未优化,但在我的测试工作正常。业绩是做动画(虽然我不认为这是一个好主意,滥用它,因为正如我说这不是优化的接受事件,它没有任何意义的使用,当然这些对于二次曲线,因为玩家可以这样做本身)。

在code是在这里,如果你想使用它,或者看看:

的BezierCurve类

样品code

我想这与样品code,你将能够找出如何使用它没有麻烦(这是相当简单的,有点评论);但是,如果你遇到问题,请走开!

随意使用它,你认为合适的。

What's the best way to draw cubic bezier curves programmatically in AS3? The Graphics class only seems to support quadratic curves. :( I want to be able to do something like:

var startPoint:Point = new Point(0, 0);
var endPoint:Point = new Point(5, 5);
var control1:Point = new Point(5, 0);
var control2:Point = new Point(0, 5);

var myBezier:Sprite = getBezier(startPoint, control1, control2, endPoint);

For a performance target, I'm planning on having ~50 of these on the stage at once.

解决方案

Note: Flash Player 11 onwards includes a native method to draw cubic curves, cubicCurveTo() which should be the fastest method if you are targeting FP11.

Just last week I wrote a class to draw Bezier curves of arbitrary order.

The code is not optimized but works fine in my tests. Performance is acceptable event for doing animations (although I don't think it's a good idea to abuse it, since as I said it's not optimized; it doesn't make sense to use these for quadratic curves, of course, since the player can do that natively).

The code is here if you want to use it or take a look:

The BezierCurve class

Sample code

I think that with the sample code you will be able to figure out how to use it without trouble (it's quite straight forward and somewhat commented); but if you run into problems, ask away!

Feel free to use it as you see fit.

这篇关于绘制三次Bezier曲线的Actionscript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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