Add a very simple image pool to limit the amount of new images loaded. Hoping it will fix the screen sometimes stopping.

This commit is contained in:
Simo Kinnunen
2015-04-27 17:01:13 +09:00
parent 2123a475e3
commit 94ea19c791
2 changed files with 26 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
function ImagePool(size) {
this.size = size
this.images = []
this.counter = 0
}
ImagePool.prototype.next = function() {
if (this.images.length < this.size) {
var image = new Image()
this.images.push(image)
return image
}
else {
if (this.counter >= this.size) {
// Reset for unlikely but theoretically possible overflow.
this.counter = 0
}
return this.images[this.counter++ % this.size]
}
}
module.exports = ImagePool