PixiJS 随机旋转和下降速度

PixiJS Random Rotation & Declining Speed

我正在尝试根据角度 属性 获得一个简单的随机数 "rotation",并希望实现以下目标。

我在此 link 上提出了我要实现的基本概念: https://www.pixiplayground.com/#/edit/yalRPEN~6tg3seIHq5hbI

在动画函数中,如果我把 let degrees = 2000;作为一个 Math.Random 值,它搞砸了动画,因为这个动画函数似乎被调用了无数次?

此外,我尝试使用速度 属性,它会以高值开始并在 "rotations" 开始变低,但它似乎什么也没做?也尝试使用 animationSpeed,因为我使用角度 属性 来改变角度,但我看不到速度差异。

如有任何反馈,我们将不胜感激。

谢谢

一种方法是改变角度而不是速度。像这样:

var angleStep = 40;
let rotateSpeed = Math.floor(Math.random() * 300)

function animate() {
    bunny.angle += angleStep;

    angleStep = angleStep - angleStep/rotateSpeed;

    if ((angleStep.toFixed(1) <= 0.0)) {
        console.log("stopped rotation")
        bunny.angle = bunny.angle;
        return bunny.angle;
    } else {
        requestAnimationFrame(animate);
    }
}