0

I am trying to port a simple JavaScript game to an Android device. I have created a Webview and put the required files into the Assets folder. I get an outline of the window on the phone but the game doesn't run. I can receive debugging messages in the console in Eclispe from the JavaScript code.

The error message im getting is:

 Uncaught TypeError: Object [object DOMWindow] has no method 'requestAnimationFrame' at file:///android_asset/www/index2.html:287

The method where the error is:

function run(){
var loop = function(){
update();
render();
window.requestAnimationFrame(loop,canvas);
}
window.requestAnimationFrame(loop,canvas);
}

Is it related to the window.requestAnimation... ? Any suggestion how I can fix it would be gratefully appreciated.. Thank you.

n4zg
  • 387
  • 2
  • 6
  • 20

1 Answers1

0

When you created your webview, did you set the following propeties?

    WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wyoskibum
  • 1,869
  • 2
  • 23
  • 43
  • Hi Thanks for the reply.. I had included the 2nd line but not the 3rd i have just added that line still the same sorry to say . – n4zg Jul 20 '14 at 15:30
  • After some research, I found the following that may be useful: http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword – wyoskibum Jul 20 '14 at 15:47
  • Thanks for that its working now on my Galaxy Note but really slow frame rate. Thanks for your time :-) – n4zg Jul 20 '14 at 15:53
  • It mentions here it is not really possible to speed the game up on android if written in JavaScript [link](http://stackoverflow.com/questions/9316803/how-to-speed-up-html5-game) – n4zg Jul 20 '14 at 16:02