BlueGit

timfa frameworkv3

fix chaining

timfa Tim · pushed by timfa

Authored 2022-10-18 · 4 years ago

Hash
7777ab803c365e1e7257272fee22b90dff840cc0
Parent
3e38d511
2 files changed +25 −8
framework/engine/image.js +9 −2
@@ -59,9 +59,16 @@ class image{
59 59 }
60 60 }
61 61
62 addAnimationCycle(label, cycle)
62 addAnimationCycle(label, cycle, loop, chain, chainDefaultIndex, chainSpeed)
63 63 {
64 this.animationCycles[label] = cycle;
64 this.animationCycles[label] =
65 {
66 frames: cycle,
67 loop: loop,
68 chain: chain,
69 chainDefaultIndex: chainDefaultIndex,
70 chainSpeed: chainSpeed
71 }
65 72 }
66 73
67 74 get width()
@@ -59,9 +59,16 @@ class image{
59 }
59 }
60 }
60 }
61
61
62 addAnimationCycle(label, cycle)
62 addAnimationCycle(label, cycle, loop, chain, chainDefaultIndex, chainSpeed)
63 {
63 {
64 this.animationCycles[label] = cycle;
64 this.animationCycles[label] =
65 {
66 frames: cycle,
67 loop: loop,
68 chain: chain,
69 chainDefaultIndex: chainDefaultIndex,
70 chainSpeed: chainSpeed
71 }
65 }
72 }
66
73
67 get width()
74 get width()
framework/engine/objectComponents/renderer.js +16 −6
@@ -32,10 +32,11 @@ class Renderer
32 32 if(this.cycle.timer > this.cycle.cycleSpeed)
33 33 {
34 34 this.cycle.timer -= this.cycle.cycleSpeed;
35 let next;
35 36
36 37 if(this.cycle.loop)
37 38 {
38 let next = (this.cycle.current + 1) % this.cycle.cycleArray.length;
39 next = (this.cycle.current + 1) % this.cycle.cycleArray.length;
39 40 }
40 41 else
41 42 {
@@ -46,14 +47,16 @@ class Renderer
46 47 this.cycle.chainDefaultIndex = this.cycle.chainDefaultIndex || this.cycle.default;
47 48 this.cycle.chainSpeed = this.cycle.chainSpeed || this.cycle.cycleSpeed;
48 49 this.setAnimation(this.cycle.chain, this.cycle.chainDefaultIndex, this.cycle.chainSpeed);
49 return;
50 50 }
51
52 return;
51 53 }
52 54 else
53 55 {
54 this.cycle.current ++;
56 next = this.cycle.current + 1;
55 57 }
56 58 }
59
57 60 this.updateCycleSprite(next)
58 61 }
59 62 }
@@ -125,14 +128,21 @@ class Renderer
125 128 return;
126 129 }
127 130 }
128
131
132 let cycleData = this.sprite.animationCycles[label];
133
129 134 this.cycle = {
130 135 label: label,
131 cycleArray: this.sprite.animationCycles[label],
136 cycleArray: cycleData.frames,
132 137 default: defaultIndex,
133 138 current: defaultIndex,
134 139 cycleSpeed: cycleSpeed,
135 timer: 0};
140 loop: cycleData.loop,
141 chain: cycleData.chain,
142 chainDefaultIndex: cycleData.chainDefaultIndex,
143 chainSpeed: cycleData.chainSpeed,
144 timer: 0
145 };
136 146
137 147 this.subImage = this.cycle.cycleArray[this.cycle.current];
138 148 }
@@ -32,10 +32,11 @@ class Renderer
32 if(this.cycle.timer > this.cycle.cycleSpeed)
32 if(this.cycle.timer > this.cycle.cycleSpeed)
33 {
33 {
34 this.cycle.timer -= this.cycle.cycleSpeed;
34 this.cycle.timer -= this.cycle.cycleSpeed;
35 let next;
35
36
36 if(this.cycle.loop)
37 if(this.cycle.loop)
37 {
38 {
38 let next = (this.cycle.current + 1) % this.cycle.cycleArray.length;
39 next = (this.cycle.current + 1) % this.cycle.cycleArray.length;
39 }
40 }
40 else
41 else
41 {
42 {
@@ -46,14 +47,16 @@ class Renderer
46 this.cycle.chainDefaultIndex = this.cycle.chainDefaultIndex || this.cycle.default;
47 this.cycle.chainDefaultIndex = this.cycle.chainDefaultIndex || this.cycle.default;
47 this.cycle.chainSpeed = this.cycle.chainSpeed || this.cycle.cycleSpeed;
48 this.cycle.chainSpeed = this.cycle.chainSpeed || this.cycle.cycleSpeed;
48 this.setAnimation(this.cycle.chain, this.cycle.chainDefaultIndex, this.cycle.chainSpeed);
49 this.setAnimation(this.cycle.chain, this.cycle.chainDefaultIndex, this.cycle.chainSpeed);
49 return;
50 }
50 }
51
52 return;
51 }
53 }
52 else
54 else
53 {
55 {
54 this.cycle.current ++;
56 next = this.cycle.current + 1;
55 }
57 }
56 }
58 }
59
57 this.updateCycleSprite(next)
60 this.updateCycleSprite(next)
58 }
61 }
59 }
62 }
@@ -125,14 +128,21 @@ class Renderer
125 return;
128 return;
126 }
129 }
127 }
130 }
128
131
132 let cycleData = this.sprite.animationCycles[label];
133
129 this.cycle = {
134 this.cycle = {
130 label: label,
135 label: label,
131 cycleArray: this.sprite.animationCycles[label],
136 cycleArray: cycleData.frames,
132 default: defaultIndex,
137 default: defaultIndex,
133 current: defaultIndex,
138 current: defaultIndex,
134 cycleSpeed: cycleSpeed,
139 cycleSpeed: cycleSpeed,
135 timer: 0};
140 loop: cycleData.loop,
141 chain: cycleData.chain,
142 chainDefaultIndex: cycleData.chainDefaultIndex,
143 chainSpeed: cycleData.chainSpeed,
144 timer: 0
145 };
136
146
137 this.subImage = this.cycle.cycleArray[this.cycle.current];
147 this.subImage = this.cycle.cycleArray[this.cycle.current];
138 }
148 }