Rohit Jain
Rohit Jain

Reputation: 831

how to speed up html5 game

Have made a typing game using HTML5 and javascript http://tweetraitor.herokuapp.com/. 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.com/rohit-jain/Tweetraitor/blob/master/app/views/guests/play.html.erb

Thanks!

Rohit Jain

Upvotes: 1

Views: 4629

Answers (2)

STeN
STeN

Reputation: 6268

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

Upvotes: 1

Patrick Desjardins
Patrick Desjardins

Reputation: 140893

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);

Upvotes: 5

Related Questions