Attaching movieclip along a path with rotation (Through AS3)

前端 未结 2 1005
南笙
南笙 2021-01-15 15:43

How could I do:

To attach a movieclip (e.g. \'footsteps\'), along a path (other movieclip).

That would be within a interval for attaching one movieclip at a

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-15 16:23

    You have to have your path as a mathematical function of t like (x,y) = f(t). In this case it's just a matter of moving a new movieclip to (x,y) and rotating it using for example Math.atan2.

    In your case it's not clear what along a path (other movieclip) means. For example, is it static or dynamic?

    The hackish way of doing this if you got a static path is using an empty sprite which is tweened along this path for 100 frames for example. In this way the function (x,y) = f(t) will be

    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);
    

    Provided that the path movieclip is called mc and the empty sprite inside is called dummy.

提交回复
热议问题