add support for nonlooping animations, animations chaining into other animations
@@ -43,7 +43,7 @@ class Game
43
43
44
44
promises.push(new Promise(resolve => {
45
45
var img = new Image();
46
var imageContext = {name: imageData.name, subImgTotal: imageData.subImgTotal, perRow: imageData.perRow};
46
var imageContext = {name: imageData.name, subImgTotal: imageData.subImgTotal, perRow: imageData.perRow, loop: imageData.loop, chain: imageData.chain};
47
47
48
48
img.onload = function() {
49
49
@@ -43,7 +43,7 @@ class Game43
43
44
promises.push(new Promise(resolve => {44
promises.push(new Promise(resolve => {45
var img = new Image();45
var img = new Image();46
var imageContext = {name: imageData.name, subImgTotal: imageData.subImgTotal, perRow: imageData.perRow};46
var imageContext = {name: imageData.name, subImgTotal: imageData.subImgTotal, perRow: imageData.perRow, loop: imageData.loop, chain: imageData.chain};47
47
48
img.onload = function() {48
img.onload = function() {49
49
@@ -1,12 +1,14 @@
1
1
class image{
2
2
subImages = null;
3
3
subImagesPerRow = null;
4
loop = false;
5
chain = null;
4
6
5
7
g_image = null;
6
8
7
9
animationCycles = {};
8
10
9
constructor(image, subImgTotal = 1, perRow = 1)
11
constructor(image, subImgTotal = 1, perRow = 1, loop = false, chain = null)
10
12
{
11
13
subImgTotal = subImgTotal || 1;
12
14
perRow = perRow || 1;
@@ -14,6 +16,8 @@ class image{
14
16
this.subImages = subImgTotal;
15
17
this.subImagesPerRow = perRow;
16
18
this.g_image = image;
19
this.loop = loop;
20
this.chain = chain;
17
21
18
22
image.id="loadedImage";
19
23
document.body.append(image);
@@ -1,12 +1,14 @@1
class image{1
class image{2
subImages = null;2
subImages = null;3
subImagesPerRow = null;3
subImagesPerRow = null;4
loop = false;5
chain = null;4
6
5
g_image = null;7
g_image = null;6
8
7
animationCycles = {};9
animationCycles = {};8
10
9
constructor(image, subImgTotal = 1, perRow = 1)11
constructor(image, subImgTotal = 1, perRow = 1, loop = false, chain = null)10
{12
{11
subImgTotal = subImgTotal || 1;13
subImgTotal = subImgTotal || 1;12
perRow = perRow || 1;14
perRow = perRow || 1;@@ -14,6 +16,8 @@ class image{14
this.subImages = subImgTotal;16
this.subImages = subImgTotal;15
this.subImagesPerRow = perRow;17
this.subImagesPerRow = perRow;16
this.g_image = image;18
this.g_image = image;19
this.loop = loop;20
this.chain = chain;17
21
18
image.id="loadedImage";22
image.id="loadedImage";19
document.body.append(image);23
document.body.append(image);@@ -33,7 +33,25 @@ class Renderer
33
33
{
34
34
this.cycle.timer -= this.cycle.cycleSpeed;
35
35
36
let next = (this.cycle.current + 1) % this.cycle.cycleArray.length;
36
if(this.cycle.loop)
37
{
38
let next = (this.cycle.current + 1) % this.cycle.cycleArray.length;
39
}
40
else
41
{
42
if(this.cycle.current + 1 > this.cycle.cycleArray.length)
43
{
44
if(this.cycle.chain)
45
{
46
this.setAnimation(this.cycle.chain, this.cycle.chainDefaultIndex, this.cycle.chainSpeed);
47
return;
48
}
49
}
50
else
51
{
52
this.cycle.current ++;
53
}
54
}
37
55
this.updateCycleSprite(next)
38
56
}
39
57
}
@@ -33,7 +33,25 @@ class Renderer33
{33
{34
this.cycle.timer -= this.cycle.cycleSpeed;34
this.cycle.timer -= this.cycle.cycleSpeed;35
35
36
let next = (this.cycle.current + 1) % this.cycle.cycleArray.length;36
if(this.cycle.loop)37
{38
let next = (this.cycle.current + 1) % this.cycle.cycleArray.length;39
}40
else41
{42
if(this.cycle.current + 1 > this.cycle.cycleArray.length)43
{44
if(this.cycle.chain)45
{46
this.setAnimation(this.cycle.chain, this.cycle.chainDefaultIndex, this.cycle.chainSpeed);47
return;48
}49
}50
else51
{52
this.cycle.current ++;53
}54
}37
this.updateCycleSprite(next)55
this.updateCycleSprite(next)38
}56
}39
}57
}