frigame3 0.0.0-stage → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +80 -2
- package/dist/Animation.d.ts +42 -0
- package/dist/Animation.js +189 -0
- package/dist/BaseSprite.d.ts +116 -0
- package/dist/BaseSprite.js +518 -0
- package/dist/Gradient.d.ts +31 -0
- package/dist/Gradient.js +89 -0
- package/dist/Playground.d.ts +48 -0
- package/dist/Playground.js +167 -0
- package/dist/Rect.d.ts +63 -0
- package/dist/Rect.js +155 -0
- package/dist/Rectangle.d.ts +31 -0
- package/dist/Rectangle.js +69 -0
- package/dist/Renderer.d.ts +23 -0
- package/dist/Renderer.js +1 -0
- package/dist/ResourceManager.d.ts +21 -0
- package/dist/ResourceManager.js +100 -0
- package/dist/Sprite.d.ts +56 -0
- package/dist/Sprite.js +437 -0
- package/dist/SpriteGroup.d.ts +39 -0
- package/dist/SpriteGroup.js +176 -0
- package/dist/canvasRenderer/renderGroup.d.ts +15 -0
- package/dist/canvasRenderer/renderGroup.js +134 -0
- package/dist/canvasRenderer/renderPlayground.d.ts +9 -0
- package/dist/canvasRenderer/renderPlayground.js +67 -0
- package/dist/canvasRenderer/renderRectangle.d.ts +15 -0
- package/dist/canvasRenderer/renderRectangle.js +287 -0
- package/dist/canvasRenderer/renderSprite.d.ts +4 -0
- package/dist/canvasRenderer/renderSprite.js +93 -0
- package/dist/canvasRenderer.d.ts +2 -0
- package/dist/canvasRenderer.js +19 -0
- package/dist/dummyRenderer.d.ts +2 -0
- package/dist/dummyRenderer.js +41 -0
- package/dist/plugins/GamepadTracker.d.ts +15 -0
- package/dist/plugins/GamepadTracker.js +74 -0
- package/dist/plugins/Tilemap.d.ts +26 -0
- package/dist/plugins/Tilemap.js +85 -0
- package/dist/plugins/Vec2.d.ts +69 -0
- package/dist/plugins/Vec2.js +296 -0
- package/dist/plugins/fx/Shaker.d.ts +46 -0
- package/dist/plugins/fx/Shaker.js +190 -0
- package/dist/plugins/fx/Tweener.d.ts +42 -0
- package/dist/plugins/fx/Tweener.js +166 -0
- package/dist/plugins/fx/easing.d.ts +32 -0
- package/dist/plugins/fx/easing.js +192 -0
- package/dist/plugins/isometric/ISOMixin.d.ts +138 -0
- package/dist/plugins/isometric/ISOMixin.js +322 -0
- package/dist/plugins/isometric/ISORectangle.d.ts +151 -0
- package/dist/plugins/isometric/ISORectangle.js +127 -0
- package/dist/plugins/isometric/ISOSprite.d.ts +157 -0
- package/dist/plugins/isometric/ISOSprite.js +176 -0
- package/dist/plugins/isometric/ISOSpriteGroup.d.ts +151 -0
- package/dist/plugins/isometric/ISOSpriteGroup.js +116 -0
- package/dist/plugins/isometric/ISOTilemap.d.ts +24 -0
- package/dist/plugins/isometric/ISOTilemap.js +85 -0
- package/dist/plugins/isometric/utils.d.ts +2 -0
- package/dist/plugins/isometric/utils.js +10 -0
- package/dist/plugins/keyTracker.d.ts +3 -0
- package/dist/plugins/keyTracker.js +23 -0
- package/dist/plugins/mixer.d.ts +72 -0
- package/dist/plugins/mixer.js +396 -0
- package/dist/plugins/sorted/SortedAnimation.d.ts +13 -0
- package/dist/plugins/sorted/SortedAnimation.js +27 -0
- package/dist/plugins/sorted/SortedGroup.d.ts +137 -0
- package/dist/plugins/sorted/SortedGroup.js +61 -0
- package/dist/plugins/sorted/SortedMixin.d.ts +122 -0
- package/dist/plugins/sorted/SortedMixin.js +153 -0
- package/dist/plugins/sorted/SortedRectangle.d.ts +127 -0
- package/dist/plugins/sorted/SortedRectangle.js +17 -0
- package/dist/plugins/sorted/SortedSprite.d.ts +130 -0
- package/dist/plugins/sorted/SortedSprite.js +35 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +33 -0
- package/frigame.css +12 -0
- package/package.json +54 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export class ResourceManager {
|
|
2
|
+
loadCallback = null;
|
|
3
|
+
// Implementation details
|
|
4
|
+
_idPreload = null;
|
|
5
|
+
_preloadList = [];
|
|
6
|
+
_resolveCallback = null;
|
|
7
|
+
_rejectCallback = null;
|
|
8
|
+
_complete = true;
|
|
9
|
+
complete() {
|
|
10
|
+
return this._complete;
|
|
11
|
+
}
|
|
12
|
+
percent() {
|
|
13
|
+
const len_preload_list = this._preloadList.length;
|
|
14
|
+
if (len_preload_list === 0) {
|
|
15
|
+
return 1;
|
|
16
|
+
}
|
|
17
|
+
const completed = this._preloadList.reduce((accumulator, resource) => accumulator + Number(resource.complete()), 0);
|
|
18
|
+
return completed / len_preload_list;
|
|
19
|
+
}
|
|
20
|
+
addResource(resource) {
|
|
21
|
+
this._preloadList.push(resource);
|
|
22
|
+
return resource;
|
|
23
|
+
}
|
|
24
|
+
removeResource(resource, options) {
|
|
25
|
+
if (resource === null) {
|
|
26
|
+
if (typeof console !== "undefined" &&
|
|
27
|
+
options?.suppressWarning === false) {
|
|
28
|
+
console.warn("resource is null");
|
|
29
|
+
console.trace();
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const index = this._preloadList.indexOf(resource);
|
|
34
|
+
if (index >= 0) {
|
|
35
|
+
this._preloadList.splice(index, 1);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (typeof console !== "undefined" &&
|
|
39
|
+
options?.suppressWarning === false) {
|
|
40
|
+
console.warn("No resources removed");
|
|
41
|
+
console.trace();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
clear() {
|
|
46
|
+
this._preloadList.splice(0, this._preloadList.length);
|
|
47
|
+
}
|
|
48
|
+
preload() {
|
|
49
|
+
const reject_callback = this._rejectCallback;
|
|
50
|
+
this._resolveCallback = null;
|
|
51
|
+
this._rejectCallback = null;
|
|
52
|
+
reject_callback?.();
|
|
53
|
+
this._complete = false;
|
|
54
|
+
// Call this._doPreload() now, in order to have the resources initialize
|
|
55
|
+
// inside the function that called resourceManager.preload().
|
|
56
|
+
// This is useful for preloading sounds in mobile environments, for
|
|
57
|
+
// example, where the sounds will not load if audio.load() is not called in
|
|
58
|
+
// an user event handler such as mousedown.
|
|
59
|
+
this._doPreload();
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
if (this._complete) {
|
|
62
|
+
resolve();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this._resolveCallback = resolve;
|
|
66
|
+
this._rejectCallback = reject;
|
|
67
|
+
if (this._idPreload === null) {
|
|
68
|
+
this._idPreload = setInterval(this._doPreload, 100);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// Implementation details
|
|
74
|
+
_doPreload = () => {
|
|
75
|
+
const completed = this._preloadList.reduce((accumulator, resource) => accumulator + Number(resource.complete()), 0);
|
|
76
|
+
const len_preload_list = this._preloadList.length;
|
|
77
|
+
const loadCallback = this.loadCallback;
|
|
78
|
+
if (completed === len_preload_list) {
|
|
79
|
+
this._complete = true;
|
|
80
|
+
if (this._idPreload !== null) {
|
|
81
|
+
clearInterval(this._idPreload);
|
|
82
|
+
this._idPreload = null;
|
|
83
|
+
}
|
|
84
|
+
for (const resource of this._preloadList) {
|
|
85
|
+
resource.onLoad();
|
|
86
|
+
}
|
|
87
|
+
this._preloadList.splice(0, len_preload_list);
|
|
88
|
+
const resolve_callback = this._resolveCallback;
|
|
89
|
+
// Set to null this._resolveCallback before calling resolve_callback
|
|
90
|
+
// in order to enable recursion
|
|
91
|
+
this._resolveCallback = null;
|
|
92
|
+
this._rejectCallback = null;
|
|
93
|
+
loadCallback?.(1);
|
|
94
|
+
resolve_callback?.();
|
|
95
|
+
}
|
|
96
|
+
else if (len_preload_list !== 0) {
|
|
97
|
+
loadCallback?.(completed / len_preload_list);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
package/dist/Sprite.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Animation, AnimationOptions } from "./Animation.js";
|
|
2
|
+
import type { BaseSpriteOptions } from "./BaseSprite.js";
|
|
3
|
+
import { BaseSprite } from "./BaseSprite.js";
|
|
4
|
+
import type { SpriteRef } from "./utils.js";
|
|
5
|
+
export interface SpriteOptions extends BaseSpriteOptions, AnimationOptions {
|
|
6
|
+
animation: Animation | null;
|
|
7
|
+
animationIndex: number;
|
|
8
|
+
callback: (() => void) | null;
|
|
9
|
+
paused: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class Sprite extends BaseSprite implements SpriteOptions {
|
|
12
|
+
_animation: Animation | null;
|
|
13
|
+
_animationIndex: number;
|
|
14
|
+
_callback: (() => void) | null;
|
|
15
|
+
_paused: boolean;
|
|
16
|
+
_rate: number;
|
|
17
|
+
_reportedRate: number;
|
|
18
|
+
_once: boolean;
|
|
19
|
+
_pingpong: boolean;
|
|
20
|
+
_backwards: boolean;
|
|
21
|
+
_idleCounter: number;
|
|
22
|
+
_lastSpriteSheet: number;
|
|
23
|
+
_currentSpriteSheet: number;
|
|
24
|
+
_numberOfFrame: number;
|
|
25
|
+
_currentFrame: number;
|
|
26
|
+
_frameIncrement: number;
|
|
27
|
+
_multix: number;
|
|
28
|
+
_multiy: number;
|
|
29
|
+
_endAnimation: boolean;
|
|
30
|
+
get animation(): Animation | null;
|
|
31
|
+
set animation(value: Animation | null);
|
|
32
|
+
get animationIndex(): number;
|
|
33
|
+
set animationIndex(value: number);
|
|
34
|
+
get callback(): (() => void) | null;
|
|
35
|
+
set callback(value: (() => void) | null);
|
|
36
|
+
get paused(): boolean;
|
|
37
|
+
set paused(value: boolean);
|
|
38
|
+
get rate(): number;
|
|
39
|
+
set rate(value: number);
|
|
40
|
+
get once(): boolean;
|
|
41
|
+
set once(value: boolean);
|
|
42
|
+
get pingpong(): boolean;
|
|
43
|
+
set pingpong(value: boolean);
|
|
44
|
+
get backwards(): boolean;
|
|
45
|
+
set backwards(value: boolean);
|
|
46
|
+
constructor(options?: Partial<SpriteOptions> & {
|
|
47
|
+
ref?: SpriteRef<Sprite>;
|
|
48
|
+
});
|
|
49
|
+
restartAnimation(): this;
|
|
50
|
+
_checkUpdate(): void;
|
|
51
|
+
_onReparent(): void;
|
|
52
|
+
_initRenderer(): void;
|
|
53
|
+
_update(): void;
|
|
54
|
+
_draw(interp: number): void;
|
|
55
|
+
_remove(): void;
|
|
56
|
+
}
|
package/dist/Sprite.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { BaseSprite } from "./BaseSprite.js";
|
|
2
|
+
import { pick } from "./utils.js";
|
|
3
|
+
export class Sprite extends BaseSprite {
|
|
4
|
+
_animation = null;
|
|
5
|
+
_animationIndex = 0;
|
|
6
|
+
_callback = null;
|
|
7
|
+
_paused = false;
|
|
8
|
+
_rate = 1;
|
|
9
|
+
_reportedRate = 0;
|
|
10
|
+
_once = false;
|
|
11
|
+
_pingpong = false;
|
|
12
|
+
_backwards = false;
|
|
13
|
+
// Implementation details
|
|
14
|
+
_idleCounter = 0;
|
|
15
|
+
_lastSpriteSheet = 0;
|
|
16
|
+
_currentSpriteSheet = 0;
|
|
17
|
+
_numberOfFrame = 0;
|
|
18
|
+
_currentFrame = 0;
|
|
19
|
+
_frameIncrement = 1;
|
|
20
|
+
_multix = 0;
|
|
21
|
+
_multiy = 0;
|
|
22
|
+
_endAnimation = false;
|
|
23
|
+
get animation() {
|
|
24
|
+
return this._animation;
|
|
25
|
+
}
|
|
26
|
+
set animation(value) {
|
|
27
|
+
if (value !== this._animation) {
|
|
28
|
+
this._animation = value;
|
|
29
|
+
if (value !== null) {
|
|
30
|
+
const playground = this.playground;
|
|
31
|
+
if (playground !== undefined) {
|
|
32
|
+
this._rate = playground.framesFromMs(value.rate);
|
|
33
|
+
}
|
|
34
|
+
this._reportedRate = value.rate;
|
|
35
|
+
this._once = value.once;
|
|
36
|
+
this._pingpong = value.pingpong;
|
|
37
|
+
this._backwards = value.backwards;
|
|
38
|
+
// Force new width and height based on the animation frame size
|
|
39
|
+
super.width = value.frameWidth;
|
|
40
|
+
super.height = value.frameHeight;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._rate = 1;
|
|
44
|
+
this._reportedRate = 0;
|
|
45
|
+
this._once = false;
|
|
46
|
+
this._pingpong = false;
|
|
47
|
+
this._backwards = false;
|
|
48
|
+
super.width = 0;
|
|
49
|
+
super.height = 0;
|
|
50
|
+
}
|
|
51
|
+
this._animationIndex = 0;
|
|
52
|
+
this.callback = null;
|
|
53
|
+
this.paused = false;
|
|
54
|
+
this.restartAnimation();
|
|
55
|
+
this._checkUpdate();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
get animationIndex() {
|
|
59
|
+
return this._animationIndex;
|
|
60
|
+
}
|
|
61
|
+
set animationIndex(value) {
|
|
62
|
+
if (value !== this._animationIndex) {
|
|
63
|
+
this._animationIndex = value;
|
|
64
|
+
this.callback = null;
|
|
65
|
+
this.paused = false;
|
|
66
|
+
this.restartAnimation();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
get callback() {
|
|
70
|
+
return this._callback;
|
|
71
|
+
}
|
|
72
|
+
set callback(value) {
|
|
73
|
+
this._callback = value;
|
|
74
|
+
this._checkUpdate();
|
|
75
|
+
}
|
|
76
|
+
get paused() {
|
|
77
|
+
return this._paused;
|
|
78
|
+
}
|
|
79
|
+
set paused(value) {
|
|
80
|
+
this._paused = value;
|
|
81
|
+
this._checkUpdate();
|
|
82
|
+
}
|
|
83
|
+
get rate() {
|
|
84
|
+
return this._reportedRate;
|
|
85
|
+
}
|
|
86
|
+
set rate(value) {
|
|
87
|
+
const playground = this.playground;
|
|
88
|
+
if (playground !== undefined) {
|
|
89
|
+
this._rate = playground.framesFromMs(value);
|
|
90
|
+
}
|
|
91
|
+
this._reportedRate = value;
|
|
92
|
+
}
|
|
93
|
+
get once() {
|
|
94
|
+
return this._once;
|
|
95
|
+
}
|
|
96
|
+
set once(value) {
|
|
97
|
+
this._once = value;
|
|
98
|
+
}
|
|
99
|
+
get pingpong() {
|
|
100
|
+
return this._pingpong;
|
|
101
|
+
}
|
|
102
|
+
set pingpong(value) {
|
|
103
|
+
this._pingpong = value;
|
|
104
|
+
}
|
|
105
|
+
get backwards() {
|
|
106
|
+
return this._backwards;
|
|
107
|
+
}
|
|
108
|
+
set backwards(value) {
|
|
109
|
+
if (value !== this._backwards) {
|
|
110
|
+
this._backwards = value;
|
|
111
|
+
this._frameIncrement *= -1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
constructor(options) {
|
|
115
|
+
super(options);
|
|
116
|
+
if (options !== undefined) {
|
|
117
|
+
Object.assign(this, pick(options, [
|
|
118
|
+
"animation",
|
|
119
|
+
"animationIndex",
|
|
120
|
+
"callback",
|
|
121
|
+
"paused",
|
|
122
|
+
"rate",
|
|
123
|
+
"once",
|
|
124
|
+
"pingpong",
|
|
125
|
+
"backwards",
|
|
126
|
+
]));
|
|
127
|
+
if (options.ref !== undefined) {
|
|
128
|
+
options.ref.current = this;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.restartAnimation();
|
|
132
|
+
this.teleport();
|
|
133
|
+
}
|
|
134
|
+
// Public functions
|
|
135
|
+
restartAnimation() {
|
|
136
|
+
const animation = this._animation;
|
|
137
|
+
if (animation !== null && this._backwards) {
|
|
138
|
+
this._lastSpriteSheet = animation.frameset.length - 1;
|
|
139
|
+
this._currentSpriteSheet = this._lastSpriteSheet;
|
|
140
|
+
this._numberOfFrame =
|
|
141
|
+
animation.frameset[this._currentSpriteSheet].numberOfFrame;
|
|
142
|
+
this._currentFrame = this._numberOfFrame - 1;
|
|
143
|
+
this._frameIncrement = -1;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this._currentSpriteSheet = 0;
|
|
147
|
+
if (animation !== null) {
|
|
148
|
+
this._lastSpriteSheet = animation.frameset.length - 1;
|
|
149
|
+
this._numberOfFrame = animation.frameset[0].numberOfFrame;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this._lastSpriteSheet = 0;
|
|
153
|
+
this._numberOfFrame = 0;
|
|
154
|
+
}
|
|
155
|
+
this._currentFrame = 0;
|
|
156
|
+
this._frameIncrement = 1;
|
|
157
|
+
}
|
|
158
|
+
this._idleCounter = 0;
|
|
159
|
+
this._endAnimation = false;
|
|
160
|
+
const index = this._animationIndex;
|
|
161
|
+
if (animation !== null && index !== 0) {
|
|
162
|
+
const sprite_sheet = animation.frameset[this._currentSpriteSheet];
|
|
163
|
+
this._multix = index * sprite_sheet._multix;
|
|
164
|
+
this._multiy = index * sprite_sheet._multiy;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this._multix = 0;
|
|
168
|
+
this._multiy = 0;
|
|
169
|
+
}
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
// Implementation details
|
|
173
|
+
_checkUpdate() {
|
|
174
|
+
const oldNeedsUpdate = this._needsUpdate;
|
|
175
|
+
if (this._endAnimation ||
|
|
176
|
+
this._paused ||
|
|
177
|
+
(this._callback === null &&
|
|
178
|
+
(this._animation === null ||
|
|
179
|
+
(this._lastSpriteSheet <= 0 && this._numberOfFrame <= 1)))) {
|
|
180
|
+
this._needsUpdate = false;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this._needsUpdate = true;
|
|
184
|
+
}
|
|
185
|
+
this._updateNeedsUpdate(oldNeedsUpdate);
|
|
186
|
+
}
|
|
187
|
+
_onReparent() {
|
|
188
|
+
const playground = this.playground;
|
|
189
|
+
if (playground !== undefined) {
|
|
190
|
+
this._rate = playground.framesFromMs(this._reportedRate);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
_initRenderer() {
|
|
194
|
+
this.playground?._renderer.initSprite(this);
|
|
195
|
+
}
|
|
196
|
+
_update() {
|
|
197
|
+
const callback = this._callback;
|
|
198
|
+
const animation = this._animation;
|
|
199
|
+
let currentSpriteSheet = this._currentSpriteSheet;
|
|
200
|
+
let currentFrame = this._currentFrame;
|
|
201
|
+
if (!(this._endAnimation || this._paused)) {
|
|
202
|
+
if (animation !== null) {
|
|
203
|
+
this._idleCounter += 1;
|
|
204
|
+
if (this._idleCounter >= this._rate) {
|
|
205
|
+
this._idleCounter = 0;
|
|
206
|
+
currentFrame += this._frameIncrement;
|
|
207
|
+
if (this._backwards) {
|
|
208
|
+
// Backwards animations
|
|
209
|
+
if (this._pingpong) {
|
|
210
|
+
// In pingpong animations the end is when the frame returns to the last frame
|
|
211
|
+
if (currentFrame >= this._numberOfFrame) {
|
|
212
|
+
if (currentSpriteSheet < this._lastSpriteSheet) {
|
|
213
|
+
currentSpriteSheet += 1;
|
|
214
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
215
|
+
this._numberOfFrame =
|
|
216
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
217
|
+
this._currentFrame = 0;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this._frameIncrement = -1;
|
|
221
|
+
if (this._once) {
|
|
222
|
+
currentFrame -= 1;
|
|
223
|
+
this._idleCounter = 1;
|
|
224
|
+
this._endAnimation = true;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// The first frame has already been displayed, start from the second
|
|
228
|
+
if (this._numberOfFrame > 1) {
|
|
229
|
+
currentFrame -= 2;
|
|
230
|
+
}
|
|
231
|
+
else if (this._lastSpriteSheet > 0) {
|
|
232
|
+
currentSpriteSheet -= 1;
|
|
233
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
234
|
+
this._numberOfFrame =
|
|
235
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
236
|
+
currentFrame = this._numberOfFrame - 1;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
currentFrame -= 1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Update the details before the callback
|
|
243
|
+
this._currentFrame = currentFrame;
|
|
244
|
+
callback?.();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else if (currentFrame < 0) {
|
|
248
|
+
if (currentSpriteSheet > 0) {
|
|
249
|
+
currentSpriteSheet -= 1;
|
|
250
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
251
|
+
this._numberOfFrame =
|
|
252
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
253
|
+
this._currentFrame = this._numberOfFrame - 1;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// Last frame reached, change animation direction
|
|
257
|
+
this._frameIncrement = 1;
|
|
258
|
+
// The first frame has already been displayed, start from the second
|
|
259
|
+
if (this._numberOfFrame > 1) {
|
|
260
|
+
currentFrame = 1;
|
|
261
|
+
}
|
|
262
|
+
else if (this._lastSpriteSheet > 0) {
|
|
263
|
+
currentSpriteSheet += 1;
|
|
264
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
265
|
+
this._numberOfFrame =
|
|
266
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
267
|
+
currentFrame = 0;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
currentFrame = 0;
|
|
271
|
+
}
|
|
272
|
+
this._currentFrame = currentFrame;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
// This is no particular frame, simply update the details
|
|
277
|
+
this._currentFrame = currentFrame;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// Normal animation
|
|
282
|
+
if (currentFrame < 0) {
|
|
283
|
+
if (currentSpriteSheet > 0) {
|
|
284
|
+
currentSpriteSheet -= 1;
|
|
285
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
286
|
+
this._numberOfFrame =
|
|
287
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
288
|
+
this._currentFrame = this._numberOfFrame - 1;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
// Last frame reached
|
|
292
|
+
if (this._once) {
|
|
293
|
+
currentFrame = 0;
|
|
294
|
+
this._idleCounter = 1;
|
|
295
|
+
this._endAnimation = true;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
currentSpriteSheet = this._lastSpriteSheet;
|
|
299
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
300
|
+
this._numberOfFrame =
|
|
301
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
302
|
+
currentFrame = this._numberOfFrame - 1;
|
|
303
|
+
}
|
|
304
|
+
// Update the details before the callback
|
|
305
|
+
this._currentFrame = currentFrame;
|
|
306
|
+
callback?.();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
// This is no particular frame, simply update the details
|
|
311
|
+
this._currentFrame = currentFrame;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
// Forwards animations
|
|
317
|
+
if (this._pingpong) {
|
|
318
|
+
// In pingpong animations the end is when the frame goes below 0
|
|
319
|
+
if (currentFrame < 0) {
|
|
320
|
+
if (currentSpriteSheet > 0) {
|
|
321
|
+
currentSpriteSheet -= 1;
|
|
322
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
323
|
+
this._numberOfFrame =
|
|
324
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
325
|
+
this._currentFrame = this._numberOfFrame - 1;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this._frameIncrement = 1;
|
|
329
|
+
if (this._once) {
|
|
330
|
+
currentFrame = 0;
|
|
331
|
+
this._idleCounter = 1;
|
|
332
|
+
this._endAnimation = true;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
// The first frame has already been displayed, start from the second
|
|
336
|
+
if (this._numberOfFrame > 1) {
|
|
337
|
+
currentFrame = 1;
|
|
338
|
+
}
|
|
339
|
+
else if (this._lastSpriteSheet > 0) {
|
|
340
|
+
currentSpriteSheet += 1;
|
|
341
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
342
|
+
this._numberOfFrame =
|
|
343
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
344
|
+
currentFrame = 0;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
currentFrame = 0;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
// Update the details before the callback
|
|
351
|
+
this._currentFrame = currentFrame;
|
|
352
|
+
callback?.();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else if (currentFrame >= this._numberOfFrame) {
|
|
356
|
+
if (currentSpriteSheet < this._lastSpriteSheet) {
|
|
357
|
+
currentSpriteSheet += 1;
|
|
358
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
359
|
+
this._numberOfFrame =
|
|
360
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
361
|
+
this._currentFrame = 0;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
// Last frame reached, change animation direction
|
|
365
|
+
this._frameIncrement = -1;
|
|
366
|
+
if (this._numberOfFrame > 1) {
|
|
367
|
+
currentFrame -= 2;
|
|
368
|
+
}
|
|
369
|
+
else if (this._lastSpriteSheet > 0) {
|
|
370
|
+
currentSpriteSheet -= 1;
|
|
371
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
372
|
+
this._numberOfFrame =
|
|
373
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
374
|
+
currentFrame = this._numberOfFrame - 1;
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
currentFrame -= 1;
|
|
378
|
+
}
|
|
379
|
+
this._currentFrame = currentFrame;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
// This is no particular frame, simply update the details
|
|
384
|
+
this._currentFrame = currentFrame;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
// Normal animation
|
|
389
|
+
if (currentFrame >= this._numberOfFrame) {
|
|
390
|
+
if (currentSpriteSheet < this._lastSpriteSheet) {
|
|
391
|
+
currentSpriteSheet += 1;
|
|
392
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
393
|
+
this._numberOfFrame =
|
|
394
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
395
|
+
this._currentFrame = 0;
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
// Last frame reached
|
|
399
|
+
if (this._once) {
|
|
400
|
+
currentFrame -= 1;
|
|
401
|
+
this._idleCounter = 1;
|
|
402
|
+
this._endAnimation = true;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
currentSpriteSheet = 0;
|
|
406
|
+
this._currentSpriteSheet = currentSpriteSheet;
|
|
407
|
+
this._numberOfFrame =
|
|
408
|
+
animation.frameset[currentSpriteSheet].numberOfFrame;
|
|
409
|
+
currentFrame = 0;
|
|
410
|
+
}
|
|
411
|
+
// Update the details before the callback
|
|
412
|
+
this._currentFrame = currentFrame;
|
|
413
|
+
callback?.();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
// This is no particular frame, simply update the details
|
|
418
|
+
this._currentFrame = currentFrame;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
// Make sure that the callback is called even if there is no animation
|
|
426
|
+
callback?.();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
_draw(interp) {
|
|
431
|
+
super._draw(interp);
|
|
432
|
+
this.playground?._renderer.drawSprite(this, interp);
|
|
433
|
+
}
|
|
434
|
+
_remove() {
|
|
435
|
+
this.playground?._renderer.removeSprite(this);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BaseSpriteOptions } from "./BaseSprite.js";
|
|
2
|
+
import { BaseSprite } from "./BaseSprite.js";
|
|
3
|
+
import type { SpriteRef } from "./utils.js";
|
|
4
|
+
export interface SpriteGroupOptions extends BaseSpriteOptions {
|
|
5
|
+
crop: boolean;
|
|
6
|
+
borderRadius: number;
|
|
7
|
+
children: BaseSprite[];
|
|
8
|
+
}
|
|
9
|
+
export declare class SpriteGroup extends BaseSprite {
|
|
10
|
+
_crop: boolean;
|
|
11
|
+
_borderRadius: number;
|
|
12
|
+
get crop(): boolean;
|
|
13
|
+
set crop(value: boolean);
|
|
14
|
+
get borderRadius(): number;
|
|
15
|
+
set borderRadius(value: number);
|
|
16
|
+
_layers: BaseSprite[];
|
|
17
|
+
_updateList: BaseSprite[];
|
|
18
|
+
constructor(options?: Partial<SpriteGroupOptions> & {
|
|
19
|
+
ref?: SpriteRef<SpriteGroup>;
|
|
20
|
+
});
|
|
21
|
+
clear(): this;
|
|
22
|
+
addChild<T extends BaseSprite>(child: T, options?: {
|
|
23
|
+
suppressWarning?: boolean;
|
|
24
|
+
}): T;
|
|
25
|
+
insertChild<T extends BaseSprite>(child: T, options?: {
|
|
26
|
+
suppressWarning?: boolean;
|
|
27
|
+
}): T;
|
|
28
|
+
removeChild(child: BaseSprite | null, options?: {
|
|
29
|
+
suppressWarning?: boolean;
|
|
30
|
+
}): this;
|
|
31
|
+
addChildren(children: BaseSprite[]): this;
|
|
32
|
+
_reparentChild(child: BaseSprite): void;
|
|
33
|
+
_addPlaygroundToChild(child: BaseSprite): void;
|
|
34
|
+
_checkUpdate(): void;
|
|
35
|
+
_initRenderer(): void;
|
|
36
|
+
_update(): void;
|
|
37
|
+
_draw(interp: number): void;
|
|
38
|
+
_remove(): void;
|
|
39
|
+
}
|