Flash 在游戏中添加计时器

Flash 在游戏中添加计时器,flash,actionscript,timer,Flash,Actionscript,Timer,每当我在flash 8中测试我的flash游戏时 计时器自动启动,我已经给我的游戏提供了菜单 进入比赛前,计时器从菜单框开始。。。 我有1帧的菜单和第二帧的汽车(其中有所有的行动脚本,包括计时器脚本),第三帧是游戏结束菜单 am还使用动态文本,变量名为_root.totaltime 问题是我的计时器没有停止仍然继续它的时间,即使游戏结束,当我点击进入时,汽车将重置,但我的计时器没有重置它的开始时间,最后离开。。。。 这是我的汽车动作脚本: onClipEvent(load) { speed =

每当我在flash 8中测试我的flash游戏时 计时器自动启动,我已经给我的游戏提供了菜单 进入比赛前,计时器从菜单框开始。。。 我有1帧的菜单和第二帧的汽车(其中有所有的行动脚本,包括计时器脚本),第三帧是游戏结束菜单 am还使用动态文本,变量名为_root.totaltime 问题是我的计时器没有停止仍然继续它的时间,即使游戏结束,当我点击进入时,汽车将重置,但我的计时器没有重置它的开始时间,最后离开。。。。 这是我的汽车动作脚本:

onClipEvent(load) 
{
speed = 0;
acceleration = 0.4;
speedDecay = 0.96;
maxSpeed = 10;
backSpeed = 1;
lap = 1;
totallaps = 4;
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)
                ++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;
    _root.totaltime.stop();
if(Key.isDown(Key.ENTER)) 
{
    _root.totaltime.start();
}
    }
onClipEvent(加载)
{
速度=0;
加速度=0.4;
速度衰减=0.96;
最大速度=10;
后退速度=1;
圈数=1;
总APS=4;
var fulllap:Boolean=false;
}
onClipEvent(enterFrame){
如果(数学abs(速度)>0.3){
速度*=速度衰减;
}否则{
速度=0;
}
if(键isDown(键UP)){
如果(数学abs(速度)>=最大速度){
速度+=加速度;
}
}
if(键isDown(键DOWN)){
如果(速度<0.5)
速度=-2;
其他的
速度--;
}
如果(数学abs(速度)>0.5){
if(键isDown(键左)){
_旋转-=10;
}
if(键isDown(键右侧)){
_旋转+=10;
}
}
x=数学sin(_旋转*(数学PI/180))*速度;
y=数学cos(_旋转*(数学PI/180))*速度*-1;
if(!_root.ground.hitTest(_x+x,_y+y,true)){
_x+=x;
_y+=y;
}否则{
速度-=速度*1.5;
}
}
onClipEvent(enterFrame){
if(_root.checkpoint1.hitTest(this)){
if(整圈){
如果(搭接>=总APS)
++圈;
满圈=假;
}   
}
if(_root.checkpoint2.hitTest(this)){
fulllap=true;
}
_root.currentlap=lap+“/”+totalaps;
秒=Math.floor(getTimer()/1000);
分钟=数学地板(秒/60);
十=数学圆((getTimer()-秒*1000)/10);
如果(分钟<10){
分钟=“0”+分钟;
}
如果(秒<10){
秒=“0”+秒;
}
如果(十位数<10){
十位数=“0”+十位数;
}
_root.totaltime=分钟+“+”秒+“+”十秒;
_root.totaltime.stop();
if(键isDown(键ENTER))
{
_root.totaltime.start();
}
}

计时器未重置。即使游戏结束,计时器仍将继续运行

我猜您正在使用ActionScript 2?就我所见,停止计时器的脚本工作得非常好。但是,这就是脚本所做的全部工作:停止计时器。它实际上并没有重置它。

标点符号将非常有用。