最近搜索

第10节 让小车实现 加速减速。

浏览:415
管理员 2021-10-28 14:48


添加变量加速度

    private _acceleration = 0.1;//加速度

image.png


修改 start  和 stop  方法

    public startRunning() {
        console.log("startr")
        this._isMove = true;
        this._speed = 0.2;
        this._acceleration = 0.2;
    }
    public stopRunning() {
        console.log("stop")
        this._acceleration = -0.2;
        //this._isMove = false;
    }


修改改update 方法

image.png


 this._speed =  this._speed + this._acceleration * dt;
            if(this._speed>this.maxSpeed){
                this._speed = this.maxSpeed;
            }
            if(this._speed < 0.01){
                this._isMove = false;
            }



联系站长

站长微信:xiaomao0055

站长QQ:14496453