Cache width and height
@@ -20,6 +20,9 @@ class image
20
20
this.loop = loop;
21
21
this.chain = chain;
22
22
23
this.cacheWidth = -1;
24
this.cacheHeight = -1;
25
23
26
image.id = "loadedImage";
24
27
document.body.append(image);
25
28
console.log("Image loaded: " + image.src);
@@ -76,14 +79,23 @@ class image
76
79
77
80
get width ()
78
81
{
79
return this.g_image.width / this.subImagesPerRow;
82
if (this.cacheWidth < 0)
83
this.g_image.width / this.subImagesPerRow;
84
85
return this.cacheWidth;
80
86
}
81
87
82
88
get height ()
83
89
{
84
return this.g_image.height / (Math.ceil(this.subImages / this.subImagesPerRow) + 0);
90
if (this.cacheHeight < 0)
91
this.g_image.height / (Math.ceil(this.subImages / this.subImagesPerRow) + 0);
92
93
return this.cacheHeight;
85
94
}
86
95
96
cacheWidth = -1;
97
cacheHeight = -1;
98
87
99
getSubImage (subImageIndex)
88
100
{
89
101
var subImage = Math.round(subImageIndex);
@@ -20,6 +20,9 @@ class image20
this.loop = loop;20
this.loop = loop;21
this.chain = chain;21
this.chain = chain;22
22
23
this.cacheWidth = -1;24
this.cacheHeight = -1;25
23
image.id = "loadedImage";26
image.id = "loadedImage";24
document.body.append(image);27
document.body.append(image);25
console.log("Image loaded: " + image.src);28
console.log("Image loaded: " + image.src);@@ -76,14 +79,23 @@ class image76
79
77
get width () 80
get width () 78
{81
{79
return this.g_image.width / this.subImagesPerRow;82
if (this.cacheWidth < 0)83
this.g_image.width / this.subImagesPerRow;84
85
return this.cacheWidth;80
}86
}81
87
82
get height () 88
get height () 83
{89
{84
return this.g_image.height / (Math.ceil(this.subImages / this.subImagesPerRow) + 0);90
if (this.cacheHeight < 0)91
this.g_image.height / (Math.ceil(this.subImages / this.subImagesPerRow) + 0);92
93
return this.cacheHeight;85
}94
}86
95
96
cacheWidth = -1;97
cacheHeight = -1;98
87
getSubImage (subImageIndex) 99
getSubImage (subImageIndex) 88
{100
{89
var subImage = Math.round(subImageIndex);101
var subImage = Math.round(subImageIndex);