简体   繁体   English

黑莓网站上的画布运动太慢

[英]canvas motion too slow on blackberry webworks

Hi I wrote a canvas animation using htlm5 and JavaScript. 嗨,我使用htlm5和JavaScript编写了画布动画。 The motion is almost normal when running on my windows browser. 在Windows浏览器上运行时,动作几乎是正常的。 But when I build it and run it on blackberry mobile, the motion decrease may ten times less faster. 但是,当我构建它并在blackberry mobile上运行它时,运动减少的速度可能会快十倍。 How can I do for that performance? 我该如何做才能表现呢? The more, I am using the form input to let users modify sizes of the graphics. 而且,我使用表单输入来让用户修改图形的大小。 But as soon as the values are modified in the text box, the graph is resized. 但是,一旦在文本框中修改了值,便会重新调整图形的大小。 How can I do to resize it only when the button is clicked? 仅当单击按钮时,如何才能调整其大小?

The problem may relate to JS performance OR canvas drawing or both. 该问题可能与JS性能或画布绘图或两者有关。 Do the following: 请执行下列操作:

1) run a non-painting related JS function a thousand times or whatever in the BB browser and see how it performs. 1)在BB浏览器中运行一千遍与绘画无关的JS函数,并查看其性能。 Some JS activites take a long time. 一些JS活动需要很长时间。 If it's ok, then it's the painting that is the problem. 如果可以的话,那就是绘画。

2) the issue with the BB Canvas tag is that clearing it, and rendering it (ie when you stop painting on in at the BB device flushes it to the screen) are both slow. 2)BB Canvas标签的问题在于,将其清除并渲染(即,当您停止在BB设备上绘画时,会将其冲洗到屏幕上)都很慢。 The actual act of calling painting functions on the canvas are not slow. 在画布上调用绘画功能的实际动作并不慢。 Also - if you are moving the canvas, BB pukes really hard, it might be reallocating entire buffers for that so it will be slow. 另外-如果您要移动画布,BB会很费劲,它可能为此重新分配了整个缓冲区,所以它会很慢。

Options: 选项:

  • slow down your animation rate - a lot. 降低动画速度-很多。 If you are re-drawing the entire widget many times a second - this will not work. 如果您每秒重新绘制整个窗口小部件多次-这将无法工作。
  • reduce the canvas to as small as possible. 将画布缩小到尽可能小。 A tiny canvas will have no problems. 一个很小的画布不会有任何问题。 A screen sized canvas takes a second to clear, and maybe 1/5 of a second to paint. 屏幕大小的画布需要一秒钟才能清除,可能需要1/5秒钟才能完成绘制。
  • don't clear any part of the canvas if you have to. 如果需要,请不要清除画布的任何部分。

All of this may mean designing an entire new form of painting ... Unfortunately, html 5 on BB just is not suited to animations. 所有这些可能意味着设计一种全新的绘画形式。不幸的是,BB上的html 5并不适合动画。 I'd strongly recommend using regular images, and then moving/replacing images as necessary using regular old html div positioning to create an animation. 我强烈建议您使用常规图像,然后使用常规旧html div定位根据需要移动/替换图像以创建动画。

Is your code optimized? 您的代码是否经过优化? I had a similar problem using JQuery for position finding, around 5000 times it took 30 sec. 使用JQuery进行位置查找时,我遇到了类似的问题,大约花了30秒钟5000次。 on ipad, I changed code from 在ipad上,我从

pos2 = jQuery('#n_'+Counter3).position().top; 
to
pos2 = document.getElementById('n_'+Counter3).offsetTop;

and it now takes less ten 1 sec. 现在只需不到10个1秒。

jQuery probably checks for different browsers as some use offset some say top etc. so it gets you the right value every time without you having to worry about browser (but probably javascript has to execute a bunch of if statements x 5000). jQuery可能会检查不同的浏览器,因为某些浏览器会使用偏移量(例如top等),因此每次都为您提供正确的值,而不必担心浏览器(但javascript必须执行一堆if语句x 5000)。

In my case I targeted IPad you are going for blackberry so optimization can speed things up without having to worry about crossbrowser compatibility. 就我而言,我针对的目标是iPad,因为您打算使用Blackberry,因此优化可以加快速度,而不必担心跨浏览器的兼容性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM