如何暂停我的功能 [英] How Do I Make A Pause To My Function

查看:144
本文介绍了如何暂停我的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我用javascript开发了一个跟踪应用程序,现在我可以使用动画功能播放我的汽车痕迹了。接下来我想创建一个功能,可以在点击暂停按钮后暂停跟踪[暂停动画]。我试过类似的事情:

Hello

I developed a tracking application with javascript and now i can play a trace of my cars using a animation function. Next I want to create a function that can pause the trace in any moment after click of the 'pause' button [pause the animation]. i tried something like :

var doChange = true;

function PAnimation() {
  if (doChange){
    PolyAnimation("../../Handler/HandlerAnimationP.ashx");
  }
}

function StopAnimation() {
  doChange = false;
}



但它不起作用。我也搜索了很多,但我发现了一些关于计时事件的事情,这对于这种情况来说是不寻常的。谢谢你的建议。


but it doesn't work how it should be. I also searched a lot but i found something about timing events and that is unusuful for this situation. Thank you for your suggestions.

推荐答案

在函数中暂停是可能的(一些阻塞调用,无论它是什么),但它对你没有帮助。这种暂停只是一个错误的想法。



动画是对的调用顺序window.requestAnimationFrame ,可选地,具有帧渲染所需的一些数据,并且通常在渲染时要考虑时间戳。如果没有这样的数据,则它可以是与帧相关联的动画相关数据,并且在每次帧更新之后计算。 暂停的一种方法是设置一个标志来停止帧更新并更改正在渲染中使用的状态机的状态。帧更新代码可以读取此标志,例如退出更新功能。



请获取我的JavaScript应用程序的源代码画布上的俄罗斯方块 ,并了解如何组织暂停。







从我的代码中,你会看到 window.requestAnimationFrame 。但是它可以基于 window.setTimeout 以一些后备方式实现,因此,基本上,这个函数仍然可以使用。有关详细信息,请参阅: http://paulirish.com/2011/requestanimationframe-for-smart-animating



-SA
"Pause in the function" is possible (some blocking call, whatever it is), but it won't help you. Such "pause" is just a wrong idea.

Animation is the sequence of the calls to window.requestAnimationFrame, optionally, with some data needed for frame rendering and, typically, time stamp to be taken into account in rendering. If there is no such data, it could be animation related data associated with the frame and calculated after each frame update. One of the ways to "pause" is to set a flag to stop frame updating and changing the state of the state machine you are using in rendering. The frame update code can read this flag and, say, exit the update function.

Please take a source code of my JavaScript application Tetris on Canvas published on CodeProject, and see how a pause can be organized.



From my code, you will see that window.requestAnimationFrame might not be available in some some browsers. But then it can be implemented in some fallback way based on window.setTimeout, so, essentially, this function still can be used. Please see for further detail: http://paulirish.com/2011/requestanimationframe-for-smart-animating.

—SA


这篇关于如何暂停我的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆