core2d 2.10.4 → 2.11.2
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/README.md +73 -0
- package/package.json +53 -48
- package/src/ACL.mjs +55 -55
- package/src/Animation.mjs +87 -50
- package/src/Axis.mjs +1 -6
- package/src/ButtonLayout.mjs +36 -36
- package/src/ButtonLayoutMap.mjs +1 -1
- package/src/Color.mjs +148 -148
- package/src/Command.mjs +10 -10
- package/src/CompositeOperations.mjs +11 -11
- package/src/Controller.mjs +85 -50
- package/src/Core2D.mjs +272 -124
- package/src/Direction.mjs +22 -22
- package/src/Engine.mjs +448 -445
- package/src/FontFamily.mjs +5 -5
- package/src/Frame.mjs +40 -16
- package/src/GamePad.mjs +43 -39
- package/src/Input.mjs +114 -111
- package/src/Key.mjs +18 -18
- package/src/KeyMap.mjs +18 -18
- package/src/Keyboard.mjs +28 -28
- package/src/Mouse.mjs +35 -23
- package/src/Point.mjs +64 -28
- package/src/Pointer.mjs +59 -37
- package/src/Rect.mjs +243 -121
- package/src/RenderableList.mjs +12 -12
- package/src/Scene.mjs +141 -100
- package/src/Sound.mjs +134 -130
- package/src/Sprite.mjs +690 -358
- package/src/Static.mjs +54 -54
- package/src/TextSprite.mjs +232 -132
- package/src/Touch.mjs +41 -29
- package/src/Transition.mjs +12 -12
- package/src/plugin/BaseTile.mjs +5 -5
- package/src/plugin/ClickableSprite.mjs +15 -16
- package/src/plugin/ControllableSprite.mjs +37 -31
- package/src/plugin/CursorSprite.mjs +33 -33
- package/src/plugin/Fog.mjs +23 -20
- package/src/plugin/FontSprite.mjs +72 -67
- package/src/plugin/JumperSprite.mjs +132 -133
- package/src/plugin/RandomRectTransition.mjs +22 -23
- package/src/plugin/Starfield.mjs +47 -45
package/src/Core2D.mjs
CHANGED
|
@@ -8,129 +8,277 @@ import { Rect } from "./Rect.mjs";
|
|
|
8
8
|
import { Scene } from "./Scene.mjs";
|
|
9
9
|
import { Sprite } from "./Sprite.mjs";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The main class of the Core2D library.
|
|
13
|
+
*/
|
|
11
14
|
export class Core2D {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the engine.
|
|
17
|
+
* @param {Scene} scene The initial scene.
|
|
18
|
+
*/
|
|
19
|
+
static init(scene) {
|
|
20
|
+
Engine.init(scene);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether the current frame is an even frame.
|
|
25
|
+
* @type {boolean}
|
|
26
|
+
*/
|
|
27
|
+
static get everyOther() {
|
|
28
|
+
return Engine.everyOther;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Adds a controller device.
|
|
33
|
+
* @param {object} device The controller device.
|
|
34
|
+
*/
|
|
35
|
+
static addControllerDevice(device) {
|
|
36
|
+
Engine.addControllerDevice(device);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Clears the canvas.
|
|
41
|
+
*/
|
|
42
|
+
static clear() {
|
|
43
|
+
Engine.clear();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Colorizes an image.
|
|
48
|
+
* @param {HTMLImageElement|HTMLCanvasElement} image The image to colorize.
|
|
49
|
+
* @param {string} fillStyle The color to use.
|
|
50
|
+
* @returns {HTMLCanvasElement} The colorized image.
|
|
51
|
+
*/
|
|
52
|
+
static colorize(image, fillStyle) {
|
|
53
|
+
return Engine.colorize(image, fillStyle);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Fades out the current theme.
|
|
58
|
+
*/
|
|
59
|
+
static fadeOut() {
|
|
60
|
+
Engine.fadeOut();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Flips an image vertically.
|
|
65
|
+
* @param {string} id The ID of the image to flip.
|
|
66
|
+
* @returns {HTMLCanvasElement} The flipped image.
|
|
67
|
+
*/
|
|
68
|
+
static flip(id) {
|
|
69
|
+
return Engine.flip(id);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets a controller.
|
|
74
|
+
* @param {number} id The ID of the controller.
|
|
75
|
+
* @returns {Controller} The controller.
|
|
76
|
+
*/
|
|
77
|
+
static getController(id) {
|
|
78
|
+
return Engine.getController(id);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets a pointer.
|
|
83
|
+
* @param {number} id The ID of the pointer.
|
|
84
|
+
* @returns {Pointer} The pointer.
|
|
85
|
+
*/
|
|
86
|
+
static getPointer(id) {
|
|
87
|
+
return Engine.getPointer(id);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets an image.
|
|
92
|
+
* @param {string} id The ID of the image.
|
|
93
|
+
* @param {boolean} isMirror Whether to mirror the image.
|
|
94
|
+
* @param {boolean} isFlip Whether to flip the image.
|
|
95
|
+
* @returns {HTMLImageElement|HTMLCanvasElement} The image.
|
|
96
|
+
*/
|
|
97
|
+
static image(id, isMirror, isFlip) {
|
|
98
|
+
return Engine.image(id, isMirror, isFlip);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Loads data from local storage.
|
|
103
|
+
* @param {string} namespace The namespace to use.
|
|
104
|
+
* @returns {object} The loaded data.
|
|
105
|
+
*/
|
|
106
|
+
static load(namespace) {
|
|
107
|
+
return Engine.load(namespace);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Mirrors an image horizontally.
|
|
112
|
+
* @param {string} id The ID of the image to mirror.
|
|
113
|
+
* @returns {HTMLCanvasElement} The mirrored image.
|
|
114
|
+
*/
|
|
115
|
+
static mirror(id) {
|
|
116
|
+
return Engine.mirror(id);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Mutes or unmutes the sound.
|
|
121
|
+
*/
|
|
122
|
+
static mute() {
|
|
123
|
+
Engine.mute();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Paints a renderable object.
|
|
128
|
+
* @param {object} renderable The renderable object.
|
|
129
|
+
* @param {number} index The layer index.
|
|
130
|
+
*/
|
|
131
|
+
static paint(renderable, index) {
|
|
132
|
+
Engine.paint(renderable, index);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Plays a sound.
|
|
137
|
+
* @param {string} id The ID of the sound to play.
|
|
138
|
+
* @param {number} volume The volume to play the sound at.
|
|
139
|
+
*/
|
|
140
|
+
static play(id, volume) {
|
|
141
|
+
Engine.play(id, volume);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Plays a theme.
|
|
146
|
+
* @param {string} name The name of the theme to play.
|
|
147
|
+
*/
|
|
148
|
+
static playTheme(name) {
|
|
149
|
+
Engine.playTheme(name);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Generates a random number.
|
|
154
|
+
* @param {number} max The maximum value.
|
|
155
|
+
* @returns {number} The random number.
|
|
156
|
+
*/
|
|
157
|
+
static random(max) {
|
|
158
|
+
return Engine.random(max);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Rotates an image.
|
|
163
|
+
* @param {HTMLImageElement|HTMLCanvasElement} image The image to rotate.
|
|
164
|
+
* @param {number} degrees The number of degrees to rotate the image.
|
|
165
|
+
* @returns {HTMLCanvasElement} The rotated image.
|
|
166
|
+
*/
|
|
167
|
+
static rotate(image, degrees) {
|
|
168
|
+
return Engine.rotate(image, degrees);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Saves data to local storage.
|
|
173
|
+
* @param {object} data The data to save.
|
|
174
|
+
* @param {string} namespace The namespace to use.
|
|
175
|
+
*/
|
|
176
|
+
static save(data, namespace) {
|
|
177
|
+
Engine.save(data, namespace);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Sets whether to automatically scale the canvas.
|
|
182
|
+
* @param {boolean} autoScale Whether to automatically scale the canvas.
|
|
183
|
+
*/
|
|
184
|
+
static setAutoScale(autoScale) {
|
|
185
|
+
Engine.setAutoScale(autoScale);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Sets the frame time.
|
|
190
|
+
* @param {number} frameTime The frame time in milliseconds.
|
|
191
|
+
*/
|
|
192
|
+
static setFrameTime(frameTime) {
|
|
193
|
+
Engine.setFrameTime(frameTime);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Sets whether to use full screen.
|
|
198
|
+
* @param {boolean} fullScreen Whether to use full screen.
|
|
199
|
+
*/
|
|
200
|
+
static setFullScreen(fullScreen) {
|
|
201
|
+
Engine.setFullScreen(fullScreen);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Sets whether to keep the aspect ratio when scaling the canvas.
|
|
206
|
+
* @param {boolean} keepAspect Whether to keep the aspect ratio.
|
|
207
|
+
*/
|
|
208
|
+
static setKeepAspect(keepAspect) {
|
|
209
|
+
Engine.setKeepAspect(keepAspect);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Sets the name of the game.
|
|
214
|
+
* @param {string} name The name of the game.
|
|
215
|
+
*/
|
|
216
|
+
static setName(name) {
|
|
217
|
+
Engine.setName(name);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Stops the current theme.
|
|
222
|
+
*/
|
|
223
|
+
static stopTheme() {
|
|
224
|
+
Engine.stopTheme();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Creates a new Animation.
|
|
229
|
+
* @param {Frame[]} frames The frames of the animation.
|
|
230
|
+
* @returns {Animation} The new animation.
|
|
231
|
+
*/
|
|
232
|
+
static animation(frames) {
|
|
233
|
+
return new Animation(frames);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Creates a new Frame.
|
|
238
|
+
* @param {HTMLImageElement|HTMLCanvasElement} image The image of the frame.
|
|
239
|
+
* @param {number} duration The duration of the frame in ticks.
|
|
240
|
+
* @returns {Frame} The new frame.
|
|
241
|
+
*/
|
|
242
|
+
static frame(image, duration) {
|
|
243
|
+
return new Frame(image, duration);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Creates a new Point.
|
|
248
|
+
* @param {number} x The x-coordinate of the point.
|
|
249
|
+
* @param {number} y The y-coordinate of the point.
|
|
250
|
+
* @returns {Point} The new point.
|
|
251
|
+
*/
|
|
252
|
+
static point(x, y) {
|
|
253
|
+
return new Point(x, y);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Creates a new Rect.
|
|
258
|
+
* @param {number} x The x-coordinate of the rectangle.
|
|
259
|
+
* @param {number} y The y-coordinate of the rectangle.
|
|
260
|
+
* @param {number} width The width of the rectangle.
|
|
261
|
+
* @param {number} height The height of the rectangle.
|
|
262
|
+
* @returns {Rect} The new rectangle.
|
|
263
|
+
*/
|
|
264
|
+
static rect(x, y, width, height) {
|
|
265
|
+
return new Rect(x, y, width, height);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Creates a new Scene.
|
|
270
|
+
* @returns {Scene} The new scene.
|
|
271
|
+
*/
|
|
272
|
+
static scene() {
|
|
273
|
+
return new Scene();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Creates a new Sprite.
|
|
278
|
+
* @param {Scene} scene The scene of the sprite.
|
|
279
|
+
* @returns {Sprite} The new sprite.
|
|
280
|
+
*/
|
|
281
|
+
static sprite(scene) {
|
|
282
|
+
return new Sprite(scene);
|
|
283
|
+
}
|
|
136
284
|
}
|
package/src/Direction.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export class Direction {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
constructor() {
|
|
5
|
+
this.bottom = false;
|
|
6
|
+
this.left = false;
|
|
7
|
+
this.right = false;
|
|
8
|
+
this.top = false;
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
setBottom(isBottom = true) {
|
|
12
|
+
this.bottom = isBottom;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
setLeft(isLeft = true) {
|
|
17
|
+
this.left = isLeft;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
setRight(isRight = true) {
|
|
22
|
+
this.right = isRight;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
setTop(isTop = true) {
|
|
27
|
+
this.top = isTop;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
30
|
}
|