core2d 2.10.3 → 2.11.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/README.md +74 -0
- package/package.json +8 -3
- package/src/ACL.mjs +3 -3
- package/src/Animation.mjs +38 -1
- package/src/Axis.mjs +1 -6
- package/src/ButtonLayout.mjs +1 -1
- package/src/ButtonLayoutMap.mjs +1 -1
- package/src/Controller.mjs +36 -1
- package/src/Core2D.mjs +150 -1
- package/src/Engine.mjs +13 -10
- package/src/Frame.mjs +24 -0
- package/src/GamePad.mjs +8 -4
- package/src/Input.mjs +5 -2
- package/src/Key.mjs +1 -1
- package/src/Keyboard.mjs +3 -3
- package/src/Mouse.mjs +23 -11
- package/src/Point.mjs +36 -0
- package/src/Pointer.mjs +24 -2
- package/src/Rect.mjs +125 -3
- package/src/Scene.mjs +44 -3
- package/src/Sound.mjs +4 -0
- package/src/Sprite.mjs +334 -8
- package/src/Static.mjs +3 -3
- package/src/TextSprite.mjs +102 -2
- package/src/Touch.mjs +26 -14
- package/src/plugin/BaseTile.mjs +1 -1
- package/src/plugin/ClickableSprite.mjs +1 -2
- package/src/plugin/ControllableSprite.mjs +9 -3
- package/src/plugin/CursorSprite.mjs +1 -1
- package/src/plugin/Fog.mjs +11 -8
- package/src/plugin/FontSprite.mjs +7 -2
- package/src/plugin/JumperSprite.mjs +0 -1
- package/src/plugin/RandomRectTransition.mjs +0 -1
- package/src/plugin/Starfield.mjs +10 -8
package/README.md
CHANGED
|
@@ -1,54 +1,128 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
3
|
# About
|
|
4
|
+
|
|
4
5
|
Core2D is the powerhouse used by [Maragato マラガト](https://maragato.itch.io) apps, among others. It is the evolution of Videogame, which in turn was the evolution of Quick. In its current form, it adopts [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), leveraging the full power of [Object-oriented programming](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_programming).
|
|
5
6
|
|
|
6
7
|
## Concept
|
|
8
|
+
|
|
7
9
|
Apps created with Core2D are made of one or more [scenes](src/Scene.mjs), which may contain one or more [sprites](src/Sprite.mjs). These objects have properties that can be customized to shape their behavior. It's that simple.
|
|
8
10
|
|
|
9
11
|
# Get Started
|
|
12
|
+
|
|
10
13
|
[Download](https://github.com/dgchrt/core2d-skel/archive/refs/heads/main.zip) or clone/fork the [skeleton project](https://github.com/dgchrt/core2d-skel/) to start building your app. Alternatively, the library can be also installed to your existing/new project:
|
|
14
|
+
|
|
11
15
|
```shell
|
|
12
16
|
npm install core2d
|
|
13
17
|
```
|
|
14
18
|
|
|
15
19
|
## Learn
|
|
20
|
+
|
|
16
21
|
The best way to learn is by doing, and you can see what Core2D is capable of through existing open-sourced apps. Check the [Hall of Fame](#hall-of-fame) below for some source code.
|
|
17
22
|
|
|
18
23
|
## Support
|
|
24
|
+
|
|
19
25
|
Please consider joining the [Discussions](https://github.com/dgchrt/core2d/discussions) for collaboration and support.
|
|
20
26
|
|
|
21
27
|
# Features
|
|
22
28
|
|
|
29
|
+
## Scene Management
|
|
30
|
+
|
|
31
|
+
Core2D facilitates the organization of your app into one or more [scenes](src/Scene.mjs), which can be transitioned between. Each scene can contain multiple [sprites](src/Sprite.mjs), which are the basic building blocks for game objects.
|
|
32
|
+
|
|
33
|
+
## Sound Management
|
|
34
|
+
|
|
35
|
+
The engine provides a simple yet powerful sound system that allows for playing sound effects and background music. It also supports fading out the current theme, which is useful for smooth transitions between different music tracks.
|
|
36
|
+
|
|
23
37
|
## Collision Detection
|
|
38
|
+
|
|
24
39
|
Translated to callbacks, to keep update logic clean.
|
|
25
40
|
|
|
26
41
|
## Assets Caching
|
|
42
|
+
|
|
27
43
|
Assets and their transformations are reused automatically to keep a solid performance.
|
|
28
44
|
|
|
45
|
+
## Transformations
|
|
46
|
+
|
|
47
|
+
Core2D provides a set of functions to manipulate images, including rotation, flipping, and colorization. These transformations are cached, so they are only applied once per image.
|
|
48
|
+
|
|
49
|
+
## Tilemap
|
|
50
|
+
|
|
51
|
+
The `Scene` class provides a `build` method that allows for creating tile-based scenes from a map. This is useful for creating levels in platformers, RPGs, and other genres that use tile-based graphics.
|
|
52
|
+
|
|
29
53
|
## User Input
|
|
54
|
+
|
|
30
55
|
Human interaction is unified via abstractions, so that apps will just work, regardless of the devices in use.
|
|
31
56
|
|
|
32
57
|
### Controllers
|
|
58
|
+
|
|
33
59
|

|
|
34
60
|
|
|
35
61
|
Gamepads or keyboard. When using a keyboard, sensible defaults (minding accessibility) are used, as seen in [KeyMap.mjs](https://github.com/dgchrt/core2d/blob/main/src/KeyMap.mjs).
|
|
36
62
|
|
|
37
63
|
### Pointers
|
|
64
|
+
|
|
38
65
|

|
|
39
66
|
|
|
40
67
|
Mice or touch screen.
|
|
41
68
|
|
|
42
69
|
## Virtual Resolution
|
|
70
|
+
|
|
43
71
|
Internal geometry frees the app logic from displays, i.e. your app can have an internal logic resolution of 800x600, while running on any display size.
|
|
44
72
|
|
|
73
|
+
# Plugins
|
|
74
|
+
|
|
75
|
+
Core2D comes with a set of optional plugins that can be used to extend its functionality. These plugins are located in the `src/plugin` directory and can be used by importing them into your project.
|
|
76
|
+
|
|
77
|
+
- **BaseTile:** A basic tile sprite that can be used with the `Scene.build` method.
|
|
78
|
+
- **ClickableSprite:** A sprite that can be clicked or tapped.
|
|
79
|
+
- **ControllableSprite:** A sprite that can be controlled by a gamepad or keyboard.
|
|
80
|
+
- **CursorSprite:** A sprite that follows the pointer.
|
|
81
|
+
- **Fog:** A simple fog effect.
|
|
82
|
+
- **FontSprite:** A sprite that displays text using a custom font.
|
|
83
|
+
- **JumperSprite:** A sprite that can jump.
|
|
84
|
+
- **RandomRectTransition:** A transition that fills the screen with random rectangles.
|
|
85
|
+
- **Starfield:** A simple starfield effect.
|
|
86
|
+
|
|
45
87
|
# Contributing
|
|
88
|
+
|
|
46
89
|
The core of the library (under `src/`) should remain agnostic and lean. Updates to the core library are usually related to technology developments in the platform (web API advances), while staying true to the basic concepts of the library, which are common to all apps.
|
|
47
90
|
|
|
48
91
|
Opinionated functionality should be implemented in the form of a plugin (under `src/plugin/`). Plugins can add features that are domain driven, such as elements that can be reused by multiple apps, but not necessarily by every app.
|
|
49
92
|
|
|
93
|
+
## Development Setup
|
|
94
|
+
|
|
95
|
+
To contribute to Core2D, you'll need to set up your development environment.
|
|
96
|
+
|
|
97
|
+
1. **Version Management:**
|
|
98
|
+
This project uses [asdf](https://asdf-vm.com/) to manage the Node.js version. To install the correct version, run:
|
|
99
|
+
```shell
|
|
100
|
+
asdf install
|
|
101
|
+
```
|
|
102
|
+
2. **Install Dependencies:**
|
|
103
|
+
```shell
|
|
104
|
+
npm install
|
|
105
|
+
```
|
|
106
|
+
3. **Recommended VS Code Extensions:**
|
|
107
|
+
This project includes a list of recommended VS Code extensions in `.vscode/extensions.json`. When you open the project in VS Code, you should be prompted to install them. These extensions will help you with code formatting and linting.
|
|
108
|
+
4. **Formatting and Linting:**
|
|
109
|
+
This project uses [Prettier](https://prettier.io/) for code formatting and [ESLint](https://eslint.org/) for linting. The configuration for these tools is in the `.prettierrc.json` and `eslint.config.js` files, respectively.
|
|
110
|
+
To format the code, run:
|
|
111
|
+
```shell
|
|
112
|
+
npm run format
|
|
113
|
+
```
|
|
114
|
+
To lint the code, run:
|
|
115
|
+
```shell
|
|
116
|
+
npm run lint
|
|
117
|
+
```
|
|
118
|
+
5. **Git Hooks:**
|
|
119
|
+
This project uses [husky](https://typicode.github.io/husky/) to manage Git hooks. A `pre-commit` hook is configured to run `npm test` before each commit. This ensures that all tests pass and the code is linted before it's committed. After running `npm install`, the hooks will be automatically configured.
|
|
120
|
+
|
|
121
|
+
|
|
50
122
|
# Hall of Fame
|
|
123
|
+
|
|
51
124
|
Apps created with Core2D:
|
|
125
|
+
|
|
52
126
|
- [Asteroids Remake](https://chamun.github.io/asteroids-remake/) ([source](https://github.com/chamun/asteroids-remake))
|
|
53
127
|
- [Cityscape](https://puter.com/app/cityscape) - Single-player arcade survival game
|
|
54
128
|
- [Cucurbita's Halloween](https://www.kongregate.com/games/bbastudios/cucurbitas-halloween)
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "core2d",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.11.1",
|
|
5
5
|
"description": "Multiplatform 2D interaction engine",
|
|
6
6
|
"files": [
|
|
7
7
|
"src"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
+
"format": "prettier --write .",
|
|
10
11
|
"lint": "eslint",
|
|
11
12
|
"prepublishOnly": "git checkout main && git pull --rebase && npm test && git push && git push --tags",
|
|
12
|
-
"test": "npm run lint && for test in ./test/*.mjs; do node $test; done"
|
|
13
|
+
"test": "npm run lint && for test in ./test/*.mjs; do node $test; done",
|
|
14
|
+
"prepare": "husky"
|
|
13
15
|
},
|
|
14
16
|
"repository": {
|
|
15
17
|
"type": "git",
|
|
@@ -45,6 +47,9 @@
|
|
|
45
47
|
"devDependencies": {
|
|
46
48
|
"@eslint/js": "^9.30.1",
|
|
47
49
|
"eslint": "^9.30.1",
|
|
48
|
-
"
|
|
50
|
+
"eslint-config-prettier": "^10.1.5",
|
|
51
|
+
"globals": "^16.3.0",
|
|
52
|
+
"husky": "^9.1.7",
|
|
53
|
+
"prettier": "^3.6.2"
|
|
49
54
|
}
|
|
50
55
|
}
|
package/src/ACL.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Sets up the environment based on its runtime (browser or not).
|
|
5
5
|
*/
|
|
6
|
-
if (typeof
|
|
6
|
+
if (typeof global != "undefined") {
|
|
7
7
|
global.addEventListener = () => {};
|
|
8
8
|
|
|
9
9
|
global.document = {
|
|
@@ -43,7 +43,7 @@ if (typeof(global) != "undefined") {
|
|
|
43
43
|
},
|
|
44
44
|
getElementsByTagName: () => {
|
|
45
45
|
return [];
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
global.localStorage = {};
|
|
@@ -59,7 +59,7 @@ if (typeof(global) != "undefined") {
|
|
|
59
59
|
focus: () => {},
|
|
60
60
|
innerHeight: 600,
|
|
61
61
|
innerWidth: 800,
|
|
62
|
-
requestAnimationFrame: () => true
|
|
62
|
+
requestAnimationFrame: () => true,
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
package/src/Animation.mjs
CHANGED
|
@@ -2,29 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
import { Frame } from "./Frame.mjs";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Represents an animation, which is a sequence of frames.
|
|
7
|
+
*/
|
|
5
8
|
export class Animation {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Animation.
|
|
11
|
+
* @param {Frame[]} frames The frames of the animation.
|
|
12
|
+
*/
|
|
6
13
|
constructor(frames) {
|
|
7
14
|
this._frames = frames;
|
|
8
15
|
this._index = 0;
|
|
9
16
|
this._tick = 0;
|
|
10
17
|
}
|
|
11
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Animation from a list of images.
|
|
21
|
+
* @param {HTMLImageElement[]|HTMLCanvasElement[]} images The images of the animation.
|
|
22
|
+
* @param {number} duration The duration of each frame in ticks.
|
|
23
|
+
* @returns {Animation} The new animation.
|
|
24
|
+
*/
|
|
12
25
|
static fromImages(images, duration) {
|
|
13
|
-
return new this(images.map(image => new Frame(image, duration)));
|
|
26
|
+
return new this(images.map((image) => new Frame(image, duration)));
|
|
14
27
|
}
|
|
15
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The image of the current frame.
|
|
31
|
+
* @type {HTMLImageElement|HTMLCanvasElement}
|
|
32
|
+
*/
|
|
16
33
|
get image() {
|
|
17
34
|
return this._frames[this._index].image;
|
|
18
35
|
}
|
|
19
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The width of the current frame.
|
|
39
|
+
* @type {number}
|
|
40
|
+
*/
|
|
20
41
|
get width() {
|
|
21
42
|
return this._frames[this._index].width;
|
|
22
43
|
}
|
|
23
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The height of the current frame.
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
24
49
|
get height() {
|
|
25
50
|
return this._frames[this._index].height;
|
|
26
51
|
}
|
|
27
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Sets the index of the current frame.
|
|
55
|
+
* @param {number} index The index of the frame.
|
|
56
|
+
*/
|
|
28
57
|
setFrameIndex(index) {
|
|
29
58
|
if (index < this._frames.length) {
|
|
30
59
|
this._index = index;
|
|
@@ -32,10 +61,18 @@ export class Animation {
|
|
|
32
61
|
}
|
|
33
62
|
}
|
|
34
63
|
|
|
64
|
+
/**
|
|
65
|
+
* The index of the current frame.
|
|
66
|
+
* @type {number}
|
|
67
|
+
*/
|
|
35
68
|
set frameIndex(index) {
|
|
36
69
|
this.setFrameIndex(index);
|
|
37
70
|
}
|
|
38
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Synchronizes the animation.
|
|
74
|
+
* @returns {boolean} Whether the animation has looped.
|
|
75
|
+
*/
|
|
39
76
|
sync() {
|
|
40
77
|
const DURATION = this._frames[this._index].duration;
|
|
41
78
|
let hasLooped = false;
|
package/src/Axis.mjs
CHANGED
package/src/ButtonLayout.mjs
CHANGED
package/src/ButtonLayoutMap.mjs
CHANGED
package/src/Controller.mjs
CHANGED
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from "./Command.mjs";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Represents a controller, which can be a gamepad or a keyboard.
|
|
7
|
+
*/
|
|
5
8
|
export class Controller {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Controller.
|
|
11
|
+
*/
|
|
6
12
|
constructor() {
|
|
13
|
+
/**
|
|
14
|
+
* The tolerance for the command sequence.
|
|
15
|
+
* @type {number}
|
|
16
|
+
*/
|
|
7
17
|
this.tolerance = 0;
|
|
8
18
|
this._active = {};
|
|
9
19
|
this._device = null;
|
|
@@ -12,9 +22,17 @@ export class Controller {
|
|
|
12
22
|
this._tick = 0;
|
|
13
23
|
}
|
|
14
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a sequence of commands was performed.
|
|
27
|
+
* @param {Command[]} commands The sequence of commands.
|
|
28
|
+
* @returns {boolean} Whether the sequence of commands was performed.
|
|
29
|
+
*/
|
|
15
30
|
didPerform(commands) {
|
|
16
31
|
for (let i = 1; i <= commands.length; ++i) {
|
|
17
|
-
if (
|
|
32
|
+
if (
|
|
33
|
+
this._sequence[this._sequence.length - i] !=
|
|
34
|
+
commands[commands.length - i]
|
|
35
|
+
) {
|
|
18
36
|
return false;
|
|
19
37
|
}
|
|
20
38
|
}
|
|
@@ -23,18 +41,35 @@ export class Controller {
|
|
|
23
41
|
return true;
|
|
24
42
|
}
|
|
25
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a command is being held down.
|
|
46
|
+
* @param {Command} command The command to check.
|
|
47
|
+
* @returns {boolean} Whether the command is being held down.
|
|
48
|
+
*/
|
|
26
49
|
keyDown(command) {
|
|
27
50
|
return this._active[command];
|
|
28
51
|
}
|
|
29
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a command was just pushed.
|
|
55
|
+
* @param {Command} command The command to check.
|
|
56
|
+
* @returns {boolean} Whether the command was just pushed.
|
|
57
|
+
*/
|
|
30
58
|
keyPush(command) {
|
|
31
59
|
return this._active[command] && !this._hold[command];
|
|
32
60
|
}
|
|
33
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Sets the device of the controller.
|
|
64
|
+
* @param {object} device The device.
|
|
65
|
+
*/
|
|
34
66
|
setDevice(device) {
|
|
35
67
|
this._device = device;
|
|
36
68
|
}
|
|
37
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Updates the controller.
|
|
72
|
+
*/
|
|
38
73
|
update() {
|
|
39
74
|
if (!this._device) {
|
|
40
75
|
return;
|
package/src/Core2D.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { Animation } from "./Animation.mjs";
|
|
3
4
|
import { Engine } from "./Engine.mjs";
|
|
4
5
|
import { Frame } from "./Frame.mjs";
|
|
5
6
|
import { Point } from "./Point.mjs";
|
|
@@ -7,128 +8,276 @@ import { Rect } from "./Rect.mjs";
|
|
|
7
8
|
import { Scene } from "./Scene.mjs";
|
|
8
9
|
import { Sprite } from "./Sprite.mjs";
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The main class of the Core2D library.
|
|
13
|
+
*/
|
|
10
14
|
export class Core2D {
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the engine.
|
|
17
|
+
* @param {Scene} scene The initial scene.
|
|
18
|
+
*/
|
|
11
19
|
static init(scene) {
|
|
12
20
|
Engine.init(scene);
|
|
13
21
|
}
|
|
14
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Whether the current frame is an even frame.
|
|
25
|
+
* @type {boolean}
|
|
26
|
+
*/
|
|
15
27
|
static get everyOther() {
|
|
16
28
|
return Engine.everyOther;
|
|
17
29
|
}
|
|
18
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Adds a controller device.
|
|
33
|
+
* @param {object} device The controller device.
|
|
34
|
+
*/
|
|
19
35
|
static addControllerDevice(device) {
|
|
20
36
|
Engine.addControllerDevice(device);
|
|
21
37
|
}
|
|
22
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Clears the canvas.
|
|
41
|
+
*/
|
|
23
42
|
static clear() {
|
|
24
43
|
Engine.clear();
|
|
25
44
|
}
|
|
26
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
|
+
*/
|
|
27
52
|
static colorize(image, fillStyle) {
|
|
28
53
|
return Engine.colorize(image, fillStyle);
|
|
29
54
|
}
|
|
30
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Fades out the current theme.
|
|
58
|
+
*/
|
|
31
59
|
static fadeOut() {
|
|
32
60
|
Engine.fadeOut();
|
|
33
61
|
}
|
|
34
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
|
+
*/
|
|
35
68
|
static flip(id) {
|
|
36
69
|
return Engine.flip(id);
|
|
37
70
|
}
|
|
38
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Gets a controller.
|
|
74
|
+
* @param {number} id The ID of the controller.
|
|
75
|
+
* @returns {Controller} The controller.
|
|
76
|
+
*/
|
|
39
77
|
static getController(id) {
|
|
40
78
|
return Engine.getController(id);
|
|
41
79
|
}
|
|
42
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Gets a pointer.
|
|
83
|
+
* @param {number} id The ID of the pointer.
|
|
84
|
+
* @returns {Pointer} The pointer.
|
|
85
|
+
*/
|
|
43
86
|
static getPointer(id) {
|
|
44
87
|
return Engine.getPointer(id);
|
|
45
88
|
}
|
|
46
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
|
+
*/
|
|
47
97
|
static image(id, isMirror, isFlip) {
|
|
48
98
|
return Engine.image(id, isMirror, isFlip);
|
|
49
99
|
}
|
|
50
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Loads data from local storage.
|
|
103
|
+
* @param {string} namespace The namespace to use.
|
|
104
|
+
* @returns {object} The loaded data.
|
|
105
|
+
*/
|
|
51
106
|
static load(namespace) {
|
|
52
107
|
return Engine.load(namespace);
|
|
53
108
|
}
|
|
54
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
|
+
*/
|
|
55
115
|
static mirror(id) {
|
|
56
116
|
return Engine.mirror(id);
|
|
57
117
|
}
|
|
58
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Mutes or unmutes the sound.
|
|
121
|
+
*/
|
|
59
122
|
static mute() {
|
|
60
123
|
Engine.mute();
|
|
61
124
|
}
|
|
62
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Paints a renderable object.
|
|
128
|
+
* @param {object} renderable The renderable object.
|
|
129
|
+
* @param {number} index The layer index.
|
|
130
|
+
*/
|
|
63
131
|
static paint(renderable, index) {
|
|
64
132
|
Engine.paint(renderable, index);
|
|
65
133
|
}
|
|
66
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
|
+
*/
|
|
67
140
|
static play(id, volume) {
|
|
68
141
|
Engine.play(id, volume);
|
|
69
142
|
}
|
|
70
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Plays a theme.
|
|
146
|
+
* @param {string} name The name of the theme to play.
|
|
147
|
+
*/
|
|
71
148
|
static playTheme(name) {
|
|
72
149
|
Engine.playTheme(name);
|
|
73
150
|
}
|
|
74
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Generates a random number.
|
|
154
|
+
* @param {number} max The maximum value.
|
|
155
|
+
* @returns {number} The random number.
|
|
156
|
+
*/
|
|
75
157
|
static random(max) {
|
|
76
158
|
return Engine.random(max);
|
|
77
159
|
}
|
|
78
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
|
+
*/
|
|
79
167
|
static rotate(image, degrees) {
|
|
80
168
|
return Engine.rotate(image, degrees);
|
|
81
169
|
}
|
|
82
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
|
+
*/
|
|
83
176
|
static save(data, namespace) {
|
|
84
177
|
Engine.save(data, namespace);
|
|
85
178
|
}
|
|
86
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Sets whether to automatically scale the canvas.
|
|
182
|
+
* @param {boolean} autoScale Whether to automatically scale the canvas.
|
|
183
|
+
*/
|
|
87
184
|
static setAutoScale(autoScale) {
|
|
88
185
|
Engine.setAutoScale(autoScale);
|
|
89
186
|
}
|
|
90
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Sets the frame time.
|
|
190
|
+
* @param {number} frameTime The frame time in milliseconds.
|
|
191
|
+
*/
|
|
91
192
|
static setFrameTime(frameTime) {
|
|
92
193
|
Engine.setFrameTime(frameTime);
|
|
93
194
|
}
|
|
94
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Sets whether to use full screen.
|
|
198
|
+
* @param {boolean} fullScreen Whether to use full screen.
|
|
199
|
+
*/
|
|
95
200
|
static setFullScreen(fullScreen) {
|
|
96
201
|
Engine.setFullScreen(fullScreen);
|
|
97
202
|
}
|
|
98
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
|
+
*/
|
|
99
208
|
static setKeepAspect(keepAspect) {
|
|
100
209
|
Engine.setKeepAspect(keepAspect);
|
|
101
210
|
}
|
|
102
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Sets the name of the game.
|
|
214
|
+
* @param {string} name The name of the game.
|
|
215
|
+
*/
|
|
103
216
|
static setName(name) {
|
|
104
217
|
Engine.setName(name);
|
|
105
218
|
}
|
|
106
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Stops the current theme.
|
|
222
|
+
*/
|
|
107
223
|
static stopTheme() {
|
|
108
224
|
Engine.stopTheme();
|
|
109
225
|
}
|
|
110
226
|
|
|
111
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Creates a new Animation.
|
|
229
|
+
* @param {Frame[]} frames The frames of the animation.
|
|
230
|
+
* @returns {Animation} The new animation.
|
|
231
|
+
*/
|
|
112
232
|
static animation(frames) {
|
|
113
233
|
return new Animation(frames);
|
|
114
234
|
}
|
|
115
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
|
+
*/
|
|
116
242
|
static frame(image, duration) {
|
|
117
243
|
return new Frame(image, duration);
|
|
118
244
|
}
|
|
119
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
|
+
*/
|
|
120
252
|
static point(x, y) {
|
|
121
253
|
return new Point(x, y);
|
|
122
254
|
}
|
|
123
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
|
+
*/
|
|
124
264
|
static rect(x, y, width, height) {
|
|
125
265
|
return new Rect(x, y, width, height);
|
|
126
266
|
}
|
|
127
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Creates a new Scene.
|
|
270
|
+
* @returns {Scene} The new scene.
|
|
271
|
+
*/
|
|
128
272
|
static scene() {
|
|
129
273
|
return new Scene();
|
|
130
274
|
}
|
|
131
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Creates a new Sprite.
|
|
278
|
+
* @param {Scene} scene The scene of the sprite.
|
|
279
|
+
* @returns {Sprite} The new sprite.
|
|
280
|
+
*/
|
|
132
281
|
static sprite(scene) {
|
|
133
282
|
return new Sprite(scene);
|
|
134
283
|
}
|