我有坦克的课程,当它被调用时它正在移动,但是这辆坦克根本没有停下来。我希望这辆坦克在它到达某个位置(位置)时停止。
package com.musuh
{
import flash.display.*;
import flash.events.*;
import flash.utils.getTimer;
public class Tank extends MovieClip
{
private var dx:Number; // speed and direction
private var lastTime:int; // animation time
private var side:String;
private var pos:Number;
private var speed:Number=2;
public function Tank(side:String, pos:int, altitude:Number)
{
this.side =side;
this.pos = pos;
if (side == "left") {
this.x = 20; // start to the left
dx = speed; // fly left to right
this.scaleX = 1; // reverse
} else if (side == "right") {
this.x = 1200; // start to the right
dx = -speed; // fly right to left
this.scaleX = -1; // not reverse
}
this.y = altitude; // vertical position
addEventListener(Event.ENTER_FRAME,moveTank);
lastTime = getTimer();
}
public function moveTank(event:Event) {
var timePassed:int = getTimer()-lastTime;
lastTime += timePassed;
// move Tank
this.x += dx*timePassed/1000;
this.y += 1;
if (this.x == pos)
{
this.x = pos;
}
}
}
}
当 this.x 到达 pos =>> 它不会停止!, 为什么 ??