Actionscript 3 沿带有旋转的路径附着电影剪辑(通过AS3)
我该怎么做: 沿路径(其他movieclip)附加movieclip(例如“足迹”) 这将是在一段时间内附加一个电影剪辑 我需要旋转,也就是说,足迹应该按照路径方向旋转Actionscript 3 沿带有旋转的路径附着电影剪辑(通过AS3),actionscript-3,Actionscript 3,我该怎么做: 沿路径(其他movieclip)附加movieclip(例如“足迹”) 这将是在一段时间内附加一个电影剪辑 我需要旋转,也就是说,足迹应该按照路径方向旋转 谢谢。你的路径必须是t的数学函数,就像(x,y)=f(t)。在这种情况下,只需将一个新的movieclip移动到(x,y),然后使用例如Math.atan2将其旋转即可 在您的情况下,不清楚路径(其他movieclip)的含义。例如,它是静态的还是动态的 如果你有一个静态的路径,你可以用一个空的精灵,沿着这个路径画100帧。这样
谢谢。你的路径必须是t的数学函数,就像
(x,y)=f(t)
。在这种情况下,只需将一个新的movieclip移动到(x,y)
,然后使用例如Math.atan2
将其旋转即可
在您的情况下,不清楚路径(其他movieclip)的含义。例如,它是静态的还是动态的
如果你有一个静态的路径,你可以用一个空的精灵,沿着这个路径画100帧。这样,函数(x,y)=f(t)
将
mc.gotoAndStop(int((t-minTime)/(maxTime-minTime)));
var xToAddFootsteps:Number = mc.dummy.x;
var yToAddFootsteps:Number = mc.dummy.y;
var rotationOfFootsteps:Number = Math.atan2(xToAddFootsteps, yToAddFootsteps);
假设路径movieclip被称为
mc
,内部的空精灵被称为dummy
1。创建坐标数组-这是您的路径。您可以通过多种方法实际创建阵列,但结果应与此类似:
var path:Array = [
Point(0, 0),
Point(20, 12),
Point(60, 72),
Point(67, 118)
];
2。设置
nextStep()。您还需要跟踪当前步骤,这可以通过简单地将您所在位置的索引存储在path数组中来表示。总之,它可能是这样的:
var currentStep:int = 0;
function nextStep():Object
{
// Object to return.
var out:Object = {
hasDestination: false,
destination: null,
radians: 0
};
var current:Point = path[currentStep];
// Check that you're not on the last step first.
if(currentStep != path.length - 1)
{
currentStep ++;
var next:Point = path[currentStep + 1];
var t:Point = next.subtract(current);
out.nextDestination = true;
out.destination = next;
out.radians = Math.atan2(t.y, t.x);
}
return out;
}
3。使用上述信息移动-从nextStep()
返回的对象可用于更改所选DisplayObject
的位置和旋转
假设实体
是您的显示对象
:
var stepInfo:Object = nextStep();
if(stepInfo.hasDestination)
{
entity.rotation = stepInfo.radians * 180 / Math.PI;
entity.x = stepInfo.destination.x;
entity.y = stepInfo.destination.y;
}
else trace("End of path reached.");
4。整理(可选)强> -考虑创建你自己的类为TyDyess的代码> > NEXSTEP()/<代码>的结果,例如:
public class StepInfo
{
public var hasDestination:Boolean = false;
public var destination:Point;
public var radians:Number = 0;
}
我甚至建议将以上所有内容移动到路径
类中,这样您就可以简单地执行以下操作:
var path:Path = new Path();
path.generate(); // create this yourself, generates the path array.
var step:StepInfo = path.nextStep();
trace(path.currentStep);
等
希望这能有所帮助。回答得很好,您可能永远不会得到这张so+1的绿色支票