问题描述
我怎么可以这样做:
要附加一个影片剪辑(如脚步声),沿路径(其它影片剪辑)。
To attach a movieclip (e.g. 'footsteps'), along a path (other movieclip).
这将是一个区间内,用于连接1影片剪辑的时间。
That would be within a interval for attaching one movieclip at a time.
我会根据与路径方向需要旋转,即脚步,应该轮换。
I would need rotation, i.e, the footsteps, should rotate according with the path direction.
感谢。
推荐答案
1。创建坐标的数组 - 这是你的路径。有许多方法可以接近实际创建阵列,但结果应该类似于此:
1. Create an array of coordinates - this is your path. There are a number of ways you can approach actually creating the array, but the result should look similar to this:
var path:Array = [
Point(0, 0),
Point(20, 12),
Point(60, 72),
Point(67, 118)
];
2。设置您的 NEXTSTEP()
功能或类似 - 这将收集有关在路径中的下一个步骤的信息,因为它和你当前步骤之间的角度。您还需要跟踪你的当前步骤,它可以重新通过简单地存储在哪里你的索引位置的路径数组中psented $ P $的。总之,它可能看起来是这样的:
2. Set up your nextStep()
function or similar - this will gather information about the next step in the path such as the angle between it and your current step. You will also need to keep track of your current step, which can be represented by simply storing the index of where you're at in the path array. Altogether, it may look like this:
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 。
3. Use the above information to move - the object returned from nextStep()
can be used to alter the position and rotation of a DisplayObject
of your choice.
假设实体
是的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。整理一下(可选) - 考虑创建自己的类是 NEXTSTEP()
为tidyness的结果,例如:
4. Tidy up (optional) - Consider creating your own class to be the result of nextStep()
for tidyness, example:
public class StepInfo
{
public var hasDestination:Boolean = false;
public var destination:Point;
public var radians:Number = 0;
}
我甚至建议将所有的上述成路径
类,所以你可以简单地做的东西,如:
I'd even suggest moving all of the above into a Path
class so you can simply do stuff like:
var path:Path = new Path();
path.generate(); // create this yourself, generates the path array.
var step:StepInfo = path.nextStep();
trace(path.currentStep);
等
希望这有助于。
这篇关于附加影片剪辑沿路径与旋转(通过AS3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!