javascript - how to speed up html5 game - Stack Overflow

admin2025-04-20  0

Have made a typing game using HTML5 and javascript /. Now I wanted to ask a couple of things

  1. Images load each time the user plays the game. Though I have used img.src to load the image at the beginning.Why is it not loading from cache?
  2. How can I speed up the game in general. The bullet firing mainly.

Code for the game area is here. .html.erb

Thanks!

Rohit Jain

Have made a typing game using HTML5 and javascript http://tweetraitor.herokuapp./. Now I wanted to ask a couple of things

  1. Images load each time the user plays the game. Though I have used img.src to load the image at the beginning.Why is it not loading from cache?
  2. How can I speed up the game in general. The bullet firing mainly.

Code for the game area is here. https://github./rohit-jain/Tweetraitor/blob/master/app/views/guests/play.html.erb

Thanks!

Rohit Jain

Share Improve this question asked Feb 16, 2012 at 18:20 Rohit JainRohit Jain 8313 gold badges12 silver badges22 bronze badges 1
  • The Animation in the background does slow down the game alot, especially if you have a bigger screen – Ibu Commented Feb 16, 2012 at 18:24
Add a ment  | 

2 Answers 2

Reset to default 5

I can tell you for the first part of the question that you may want to try to cache the images in base64 into the localstorage of the user. This way, the data will already be loaded client side and won't require the client to download everything.

Here is a blog post about how to do it . In short, you have to check if the image is in the local storage

if ( localStorage.getItem('myImageId')) {

if not to save it into it

 localStorage.setItem('myImageId',image);

our general experience with HTML5/JavaScript/CSS based games on Android is that it is very slow - we have games we are using across platforms (desktop, TVs, iPhone) but for the Android we rewrite them natively in Java...

Even simple games like pong (the bouncing ball) are slow even on new devices. The situation is much worse when you try it on underpowered ~100-150 EUR devices from ZTE, Huawei or HTC.

If you will find out some general solution we will be more then happy to use it, but i doubt there is any. Does not matter if you are using some framework (i.e. Sencha touch) or not.

See there also.

Regards, STeN

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745114310a285771.html

最新回复(0)