我目前正在尝试制作道路运动动画,但无法确定道路如何不能自行扩展。 整个代码不是我的,它来自一个教程,我只是试图根据我的需要修改它,但我不能做道路应该移动的部分,就像我从上面看到它(鸟瞰图),总是以相同的速度。 目前我有这个swf文件
http://www.stouchgames.com/APKs/Road.swf
我不希望它像顶部的小线条,然后在底部的一条大线移动。我只想同样是从上到下移动的大线。 到目前为止,我有一个简单的movieClip有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框架功能时,我不能让它们顺利移动......并且决定必须通过第一道道因为更详细的结局和原因最终如果我想要改变道路的分辨率我可以用它做得更容易。当然,我可能是错的,因为我之前没有做过这样的事情。
有人可以帮忙吗?
答案 0 :(得分:0)
在竞赛功能中将 yMap [i] 替换为 i :
for (var i:int = 0; i < roadLines; i++) {
if ((i + texOffset) % 100 > 50) {
lines[i].gotoAndStop(1);
} else {
lines[i].gotoAndStop(2);
}
}