AS2:椭圆周围的补间

发布于 2024-11-15 18:25:47 字数 299 浏览 4 评论 0原文

我在舞台上有 7 个影片剪辑,我想从不同的起点围绕椭圆进行补间。我在做这件事时遇到了很多麻烦......我首先使用了圆形公式,然后将 y 值除以椭圆的宽度除以高度。这种方法可行,但每次旋转后 y 值都会变小。该代码是:

this._x += (Math.cos(angle * Math.PI/180) * radius); this._y += (Math.sin(角度 * Math.PI/180) *半径)/1.54;

我也很难找到起点的角度,如果它关闭,它们将不会在同一个椭圆中行进,但它们都有不同的起始角度。

有什么线索吗?

I have 7 movieclips on stage I want to tween around an ellipse from different start points. I am having lots of trouble doing this.... I used a circle formula at first and then divided the y value by the width of the ellipse over the height. This sort of worked but after every rotation the y value was a little of. That code is:

this._x += (Math.cos(angle * Math.PI/180) * radius);
this._y += (Math.sin(angle * Math.PI/180) *radius)/1.54;

I also have trouble finding the angle of the start point, if it is off they won't travel in the same ellipse but they all have different starting angles.

Any clues?

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

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

发布评论

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

评论(2

夜雨飘雪 2024-11-22 18:25:47

使用以下代码片段计算个别偏移量:

// assuming you have your buttons in an array called buttons
for (var i:Number = 0; i < buttons.length; i++){
    buttons[i].angleOffset = 360 / buttons.length * i;
}

设置每次更新的位置而不是移动,这样就不会产生任何漂移。
使用此代码更新每个对象,增加 angle 变量以使其旋转。

    this._x = offsetX + Math.sin((angle + angleOffset) * Math.PI/180) * radius; 
    this._y = offsetY + Math.cos((angle + angleOffset) * Math.PI/180) * radius / 1.54;

Calculate the incidvidual offsets using this snippet:

// assuming you have your buttons in an array called buttons
for (var i:Number = 0; i < buttons.length; i++){
    buttons[i].angleOffset = 360 / buttons.length * i;
}

Set the position each update instead of moving, that way you wont get any drift.
Update each object using this code, incrementing the angle var to get it to spin.

    this._x = offsetX + Math.sin((angle + angleOffset) * Math.PI/180) * radius; 
    this._y = offsetY + Math.cos((angle + angleOffset) * Math.PI/180) * radius / 1.54;
明媚如初 2024-11-22 18:25:47

这几乎是解决了,这段脚本将获取数组按钮的项目(可以添加任意数量),将它们围绕您设置的椭圆(原点+半径)间隔开,并根据您的速度在其周围补间它们放。唯一的问题是间距不均匀,有些很近,有些很远,我不明白为什么。

var angle:Number = 0;
var originX:Number = 200;
var originY:Number = 200;
var radiusX:Number = 267.5;
var radiusY:Number = 100;
var steps:Number = 360;
var speed:Number = 3.1415/steps;
var buttons:Array = new Array(this.age,this.ethnicity,this.sex,this.social,this.ability,this.orientation,this.faith);

for (i=0;i<buttons.length;i++) {
buttons[i].onEnterFrame = function() {
    moveButtons(this);
    controllButtons(this);
};
buttons[i]._order = (360/buttons.length) * (i+1);
}
function moveButtons(e) {
    e._anglePhase = angle+e._order;
    e._x = originX+Math.sin(e._anglePhase)*radiusX;
    e._y = originY+Math.cos(e._anglePhase)*radiusY;
}

function controllButtons(e) {
    angle += speed;
    if (angle>=360) {
        angle -= 360;
    }
}

请注意,我从 http://www 获取此脚本的基础.actionscript.org/forums/showthread.php3?t=161830&page=2 将其转换为 AS2 并使其通过数组工作。

This is almost soved, this piece of script will take the items of the array buttons (can add as many as you want), space them around the ellipse you set (origin + radius), and tween them around it according to the speed you set. The only problem is the spacing isn't even and some are close and some far apart and I don't understand why.

var angle:Number = 0;
var originX:Number = 200;
var originY:Number = 200;
var radiusX:Number = 267.5;
var radiusY:Number = 100;
var steps:Number = 360;
var speed:Number = 3.1415/steps;
var buttons:Array = new Array(this.age,this.ethnicity,this.sex,this.social,this.ability,this.orientation,this.faith);

for (i=0;i<buttons.length;i++) {
buttons[i].onEnterFrame = function() {
    moveButtons(this);
    controllButtons(this);
};
buttons[i]._order = (360/buttons.length) * (i+1);
}
function moveButtons(e) {
    e._anglePhase = angle+e._order;
    e._x = originX+Math.sin(e._anglePhase)*radiusX;
    e._y = originY+Math.cos(e._anglePhase)*radiusY;
}

function controllButtons(e) {
    angle += speed;
    if (angle>=360) {
        angle -= 360;
    }
}

Please note I got the base of this script from http://www.actionscript.org/forums/showthread.php3?t=161830&page=2 converted it to AS2 and made it work from an array.

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