【问题标题】:Calculating the trajectory arc of a projectile计算弹丸的轨迹弧
【发布时间】:2017-12-05 06:11:45
【问题描述】:

我正在尝试以弧形在屏幕上移动图像...想想飞扬的小鸟发射器。图像从屏幕的左下方开始。当“启动”时,我希望它像启动一样在屏幕上以弧线移动/动画。

我可以以线性(向上和向右)轨迹为图像设置动画,但不知道如何使其弯曲并开始下降。

图像位于屏幕的左下方。

在每 0.01 秒运行一次的 setTimeout 方法中:

left += 10;
top -= 10;
$image.animate({left: '' + left + 'px', top: '' + top + 'px' });

【问题讨论】:

    标签: javascript jquery css jquery-animate physics


    【解决方案1】:

    跟踪速度和位置。

    const GRAVITY = 2; // acceleration due to gravity, in pixels/tick
    x = 0;
    y = 0;
    deltaX = 10;
    deltaY = -10;
    
    function tick() { // your setTimeout method
      x += deltaX;
      y += deltaY;
      deltaY += GRAVITY;
      $image.animate({left: `${x}px`, top: `${y}px` });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      相关资源
      最近更新 更多