Slowdown in JavaScript game on a laptop
I wrote a game in JavaScript/jQuery that uses a timer to update the character periodically. It works fine in a browser but when I run it in Ogre (via the Awesomium plug-in) there is a significant slow-down, although it still runs acceptably fast on my workstation. However, when run on a laptop with lower specs, it runs very slowly, it is not even playable.
Here is the relevant code:
This is the main game file that starts the timer and calls the Update function of the main character:
- const TIMER_INTERVAL = 0.001;
- // Start the game
- var newBiology = new Game("newBiology", TIMER_INTERVAL);
- function Game(varName, interval)
- {
- this.update = function()
- {
- // Update the bee.
- myBee.update(this.mUpdateInterval);
- }
- setInterval(varName + ".update()", TIMER_INTERVAL * 1000);
- this.mUpdateInterval = interval;
- }
And this is the main character's class:
- function Bee(node)
- {
- this.Node = node;
-
- this.moveLeft = function()
- {
- _x -= _speed;
- _parent.css({ "left": _x + "px" });
- }
-
- this.moveRight = function()
- {
- _x += _speed;
- _parent.css({ "left": _x + "px" });
- }
-
- this.update = function(timeSinceLastCall)
- {
- if (_moveLeft)
- {
- this.moveLeft();
- } // End if
- else if (_moveRight)
- {
- this.moveRight();
- } // End else if
- else if (_moveDown)
- {
- this.moveDown();
- } // End else if
- else if (_moveUp)
- {
- this.moveUp();
- } // End else if
- }
Anybody have any ideas why it would be so slow on a laptop with lower specs?