最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - PhoneGap games, canvas and slow javascript - Stack Overflow

programmeradmin7浏览0评论

So I built what I hoped would bee a simple android game. I first built a web version to getting it working () then moved it to PhoneGap and used accelerometers to control the game. The only problem (and it's a show stopping problem) is that the result is horrifically slow (updates i guess about once a second instead of ever 20ms ish).

Is this just how slow phonegap is, with no current solution? Or is there some golden bullet I'm missing?

The game uses easeljs and box2d-web.

What's odd is it seems to run at a reasonable speed on android chrome, but very slow on android's "browser" (which I seem to recall is based on firefox?) and in phonegap which presumably uses the same html renderer/js interrupter.

I've tried simplifying the game, getting rid of as much as i can, using setInterval rather than accelerometer.watchAcceleration all to no avail.

So I built what I hoped would bee a simple android game. I first built a web version to getting it working (http://scolvin./ballgame) then moved it to PhoneGap and used accelerometers to control the game. The only problem (and it's a show stopping problem) is that the result is horrifically slow (updates i guess about once a second instead of ever 20ms ish).

Is this just how slow phonegap is, with no current solution? Or is there some golden bullet I'm missing?

The game uses easeljs and box2d-web.

What's odd is it seems to run at a reasonable speed on android chrome, but very slow on android's "browser" (which I seem to recall is based on firefox?) and in phonegap which presumably uses the same html renderer/js interrupter.

I've tried simplifying the game, getting rid of as much as i can, using setInterval rather than accelerometer.watchAcceleration all to no avail.

Share Improve this question edited Mar 29, 2014 at 17:46 Samuel Colvin asked Apr 10, 2013 at 12:33 Samuel ColvinSamuel Colvin 13.4k7 gold badges63 silver badges78 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

It's a problem of the Android Browser

See the following answer:

Sencha Touch 2 - Android Performance

(It's for Sencha Touch, but i think the main points of the answer are the same)

Instead of using setInterval() for FPS thing, you must use requestAnimationFrame() It is far more efficient

iOS 5+ and Android 3+ use hardware acceleration for Canvas, so you will need atleast those devices for solid performance. Anything before iOS 5.0 and Android 3.0 will use CPU using software-rendering.

So need to keep that in mind

Is the performance issue with rendering or reading the accelerometer? Maybe you could create a demo mode to check how it behaves without user input.

发布评论

评论列表(0)

  1. 暂无评论