0

我目前正在尝试制作道路运动动画,但无法弄清楚道路如何不能自行缩放。整个代码不是我的,它来自一个教程,我只是试图根据我的需要修改它,但我不能做道路应该移动的部分,如果我从上面看到它(鸟瞰图),总是以相同的速度. 目前我有这个 swf 文件

http://www.stouchgames.com/APKs/Road.swf

我不希望它像顶部的小线,然后在底部移动的大线。我只想成为同样从上到下移动的大线。到目前为止,我有一个带有 2 帧的简单电影剪辑,并且帧中有这张图片中的图形:

http://stouchgames.com/APKs/road.jpg

这个代码:

package {

      import flash.display.MovieClip;
      import flash.events.Event;

      public class Main extends MovieClip {

                //Depth of the visible road
                private const roadLines:int = 320;
                //Dimensions of the play area.
                private const resX:int = 480;
                private const resY:int = 320;
                //Line of the player's car.
                private const noScaleLine:int = 8;
                //All the road lines will be accessed from an Array.
                private var yMap:Array = [];
                private var lines:Array = [];
                private var halfWidth:Number;
                private var lineDepth:int;
                private const widthStep:Number = 0;

                private var playerY:Number;

                private var speed:int = 2;
                private var texOffset:int = 100;


                public function Main() {
                          //Populate the zMap with the depth of the road lines
                          for (var i:int = 0; i < roadLines; i++) {
                                    yMap.push(1 / (i - resY));
                          }

                          playerY = 100 / yMap[noScaleLine];


                          for (i = 0; i < roadLines; i++) {
                                    yMap[i] *=  playerY;
                          }
                          //Make the line at the bottom to be in front of the rest,
                          //and add every line at the same position, bottom first.
                          lineDepth = numChildren;
                          for (i = 0; i < roadLines; i++) {
                                    var line = new Road();
                                    lines.push(line);
                                    addChildAt(line, lineDepth);
                                    line.x = resX / 2;
                                    line.y = resY - i;
                          }
                          //Scaling the road lines according to their position

                         addEventListener(Event.ENTER_FRAME, race);
                }

                private function race(event:Event):void {
                          for (var i:int = 0; i < roadLines; i++) {
                                    if ((yMap[i] + texOffset) % 100 > 50) {
                                              lines[i].gotoAndStop(1);
                                    } else {
                                              lines[i].gotoAndStop(2);
                                    }
                          }
                          texOffset = texOffset + speed;
                          while (texOffset >= 100) {
                                    texOffset -=  100;
                          }
                }
      }

}

我确实尝试只用不同的图形制作 2 路电影剪辑,然后使用

for (var i:int = 0; i < 8; i++) {

            if (((i % 2) == 0)) {
                var line = new Road  ;
                lines.push(line);
                addChildAt(line,lineDepth);
                line.x = resX / 2;
                line.y = resY - i * 50;
                line.alpha = .2;
            }
            if (((i % 2) == 1)) {
                var line = new Road2  ;
                lines.push(line);
                addChildAt(line,lineDepth);
                line.x = resX / 2;
                line.y = resY - i * 50;
                line.alpha = .5;
            }

但是当我进入 Event.EVERY 框架功能时,我无法让它们顺利移动......并决定必须通过第一种方式完成,因为更详细的结局和最终导致如果我想更改分辨率我可以用它更轻松地完成这条路。当然我可能是错的,因为我以前没有做过这样的事情。

那么有人可以帮忙吗?

4

1 回答 1

0

在竞赛函数中用i替换yMap[i] :

for (var i:int = 0; i < roadLines; i++) {
    if ((i + texOffset) % 100 > 50) {
         lines[i].gotoAndStop(1);
    } else {
         lines[i].gotoAndStop(2);
    }
}
于 2013-08-26T18:00:59.623 回答