小编jux*_*jux的帖子

每次我再次运行时动画变得越来越快

我有一个简单的动画,它只是一个立方体,可以向不同方向旋转。

问题是当我单击运行按钮时,动画每次都会变得越来越快(尝试多次单击运行)。我想 gl_draw() 函数有问题,但为什么会这样,我该如何简单地修复它?

function gl_draw() {
// set the color to transparent
gl_ctx.clearColor(0.0, 0.0, 0.0, 0.0);
// enable Depth buffer test and set depth buffer comparison function
gl_ctx.enable(gl_ctx.DEPTH_TEST);
gl_ctx.depthFunc(gl_ctx.LEQUAL);

// set the clear value for the depth buffer to 1
gl_ctx.clearDepth(1.0);

var timeOld = 0;

var animate = function (time) {
  var dAngle = rotationSpeed * (time - timeOld);

  if (X) {
     MATRIX.rotateX(_matrixMovement, dAngle);
  }
  if (Y) {
     MATRIX.rotateY(_matrixMovement, dAngle);
  }
  if (Z) {
     MATRIX.rotateZ(_matrixMovement, dAngle);
  }

  timeOld = …
Run Code Online (Sandbox Code Playgroud)

javascript canvas html5-canvas

4
推荐指数
1
解决办法
602
查看次数

标签 统计

canvas ×1

html5-canvas ×1

javascript ×1