Update function (dt) 里面的dt是代表什么含义?

// Player.js
    update: function (dt) {
        // 根据当前加速度方向每帧更新速度
        if (this.accLeft) {
            this.xSpeed -= this.accel * dt;
        } else if (this.accRight) {
            this.xSpeed += this.accel * dt;
        }
        // 限制主角的速度不能超过最大值
        if ( Math.abs(this.xSpeed) > this.maxMoveSpeed ) {
            // if speed reach limit, use max speed with current direction
            this.xSpeed = this.maxMoveSpeed * this.xSpeed / Math.abs(this.xSpeed);
        }

        // 根据当前速度更新主角的位置
        this.node.x += this.xSpeed * dt;
    },

dt是什么参数。

dt应该是delta time,就是两次update之间的间隔时间,单位“可能是”毫秒

4赞

官方吃星星小项目的一直没找到对应参数,猜是源码里面的。

为啥是“可能”??

围观。

围观.

因为王哲好久没有敲代码了,已经忘记了,其实就是毫秒

1赞

单位应该是秒把,如果单位是毫秒那这个数在16-17左右,这样this.accel * dt这个数就很大了,如果是秒,dt也就是0.017左右,

你号没了