简体   繁体   English

iOS HTML Canvas或CSS3 3D转换

[英]IOS HTML Canvas or CSS3 3D Transforms

On the IOS platform: 在IOS平台上:

The HTML5 canvas element is not hardware accelerated. HTML5 canvas元素不是硬件加速的。 CSS3 3D Transforms (example: translate3d ) are hardware accelerated. CSS3 3D转换(例如: translate3d )是硬件加速的。

Looking to create a 2d game for IOS using HTML/JavaScript with PhoneGap, should I consider using just the DOM with CSS3? 希望使用带PhoneGap的HTML / JavaScript为IOS创建2D游戏,我是否应该考虑仅将CSS和DOM一起使用?

Has anyone tried this? 有人尝试过吗? Are there any benchmarks? 有基准吗?

I also had this concern when building my own 2D game. 在构建自己的2D游戏时,我也有这种担忧。 I initially had problems with animation performance on iOS but I solved it with CSS3 3D transformations. 最初,我在iOS上的动画性能存在问题,但是我通过CSS3 3D转换解决了该问题。 I didn't try Canvas but I really didn't need to once the proper CSS was applied. 我没有尝试过Canvas,但是一旦应用了正确的CSS,我真的不需要。 And the performance remained good with PhoneGap under both iOS and Android versions. 在iOS和Android版本下,PhoneGap的性能仍然很好。 Some older Android devices are somewhat slow but I don't think Canvas would help with that either. 一些较旧的Android设备运行缓慢,但是我也不认为Canvas可以帮助解决这一问题。

As for benchmarking, I did find this which shows both Canvas and CSS3 transitions with images: http://www.spielzeugz.de/html5/compare/ 至于基准测试,我确实发现它可以同时显示Canvas和CSS3转换以及图像: http : //www.spielzeugz.de/html5/compare/

The accepted answer is actually extremely misleading, as are parts of the question. 接受的答案实际上是极具误导性的,也是问题的一部分。 To set things straight: 弄清楚点:

  • iOS 5 and up actually do use hardware acceleration for Canvas. iOS 5及更高版本实际上确实为Canvas使用了硬件加速。
  • The canvas is not pretty well designed, at all. 画布的设计不是很好。 Hardware acceleration only kicks in if you apply transforms. 如果应用变换,则只会启动硬件加速。 If you clear and redraw, even with requestAnimationFrame your performance may still very well be choppy. 如果清除并重画,即使使用requestAnimationFrame,您的表现也可能会非常不稳定。 You are definitely going to notice differences. 您肯定会注意到差异。
  • CSS3 transforms may yield better performance - for Android devices. CSS3转换可能会产生更好的性能-适用于Android设备。

I made an attempt but lost interest. 我尝试了一下,但失去了兴趣。 It seemed to be just as efficient as doing the same thing I was doing with canvases. 这似乎和我对画布所做的事情一样有效。 You're not going to notice much difference unless you're doing heavy javascript calculations which you will probably be doing regardless of whether you use CSS3 or canvas. 除非您进行大量的javascript计算(无论使用CSS3还是canvas),否则您不会注意到很大的不同。

I don't know of any benchmarks but you can read about it here: http://www.sencha.com/blog/apple-ios-5-html5-developer-scorecard/ 我不知道任何基准,但您可以在此处阅读有关它的信息: http : //www.sencha.com/blog/apple-ios-5-html5-developer-scorecard/

It is also going to depend on which device you're talking about. 它还将取决于您正在谈论的设备。 They all run different hardware and slightly different software so that should affect your decision: http://www.codefessions.com/2012/03/how-fast-is-html5-canvas-part-2.html 它们都运行不同的硬件和略有不同的软件,因此应该会影响您的决定: http : //www.codefessions.com/2012/03/how-fast-is-html5-canvas-part-2.html

Canvas is pretty well designed, in a way such that it isn't going to make much of a difference whether you hardware accelerate it or not, especially if you're just doing 2d stuff. Canvas的设计相当不错,无论您是否通过硬件对其进行加速都不会产生太大的影响,尤其是在您只是做2D东西时。

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

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