我对此很陌生......试图在一个简单的赛车游戏中启动计时器。我直接在对象(汽车)上执行操作,并希望计时器在您第一次开始按下键盘上的一个操作按钮时启动,从左到右。现在它在电影本身开始时就开始了,甚至在第一个场景中。任何帮助将不胜感激!
汽车代码:
onClipEvent(load) {
speed = 0;
acceleration = 0.4;
speedDecay = 0.96;
maxSpeed = 10;
backSpeed = 1;
lap = 1;
totallaps = 3;
var fulllap:Boolean = false;
}
onClipEvent(enterFrame) {
if(Math.abs(speed) > 0.3) {
speed *= speedDecay;
}else {
speed = 0;
}
if(Key.isDown(Key.UP)) {
if (Math.abs(speed) >= maxspeed) {
speed += acceleration;
}
}
if(Key.isDown(Key.DOWN)) {
if(speed < 0.5)
speed = -2;
else
speed--;
}
if (Math.abs(speed)> 0.5) {
if (Key.isDown(Key.LEFT)) {
_rotation -= 10;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 10;
}
}
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.ground.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
}else {
speed -= speed*1.5;
}
}
onClipEvent(enterFrame) {
if (_root.checkpoint1.hitTest(this)) {
if(fulllap){
if(lap >= totallaps)
_root.gotoAndPlay("end");
++lap;
fulllap = false;
}
}
if (_root.checkpoint2.hitTest(this)) {
fulllap = true;
}
_root.currentlap = lap + "/" + totallaps;
seconds = Math.floor(getTimer()/1000);
minutes = Math.floor(seconds/60);
tens = Math.round((getTimer()-seconds*1000)/10);
if(minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
if (tens < 10 ) {
tens = "0" + tens;
}
_root.totaltime = minutes + "." + seconds + "." + tens;
}
在这个场景之前有一个场景,有一个按钮可以进入游戏部分。电影一开始,计时器就开始计时。我希望它在游戏开始以某种方式开始播放时开始。