angry-pixel 1.2.3 → 1.2.5
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 +170 -168
- package/api-docs/.nojekyll +1 -0
- package/api-docs/assets/highlight.css +92 -0
- package/api-docs/assets/main.js +59 -0
- package/api-docs/assets/navigation.js +1 -0
- package/api-docs/assets/search.js +1 -0
- package/api-docs/assets/style.css +1383 -0
- package/api-docs/classes/Animator.html +128 -0
- package/api-docs/classes/AudioPlayer.html +131 -0
- package/api-docs/classes/BallCollider.html +132 -0
- package/api-docs/classes/BoxCollider.html +136 -0
- package/api-docs/classes/Button.html +125 -0
- package/api-docs/classes/Camera.html +114 -0
- package/api-docs/classes/Component.html +106 -0
- package/api-docs/classes/EdgeCollider.html +134 -0
- package/api-docs/classes/Game.html +24 -0
- package/api-docs/classes/GameCamera.html +163 -0
- package/api-docs/classes/GameObject.html +149 -0
- package/api-docs/classes/GamepadController.html +11 -0
- package/api-docs/classes/GamepadData.html +81 -0
- package/api-docs/classes/KeyboardController.html +43 -0
- package/api-docs/classes/MaskRenderer.html +119 -0
- package/api-docs/classes/MouseController.html +14 -0
- package/api-docs/classes/PhysicsComponent.html +107 -0
- package/api-docs/classes/PolygonCollider.html +134 -0
- package/api-docs/classes/PreRenderComponent.html +107 -0
- package/api-docs/classes/Rectangle.html +30 -0
- package/api-docs/classes/RigidBody.html +123 -0
- package/api-docs/classes/Rotation.html +5 -0
- package/api-docs/classes/Scene.html +73 -0
- package/api-docs/classes/SpacePointer.html +147 -0
- package/api-docs/classes/Sprite.html +20 -0
- package/api-docs/classes/SpriteRenderer.html +134 -0
- package/api-docs/classes/TextRenderer.html +138 -0
- package/api-docs/classes/TiledTilemapRenderer.html +127 -0
- package/api-docs/classes/TilemapCollider.html +124 -0
- package/api-docs/classes/TilemapRenderer.html +126 -0
- package/api-docs/classes/TouchController.html +8 -0
- package/api-docs/classes/Transform.html +124 -0
- package/api-docs/classes/Vector2.html +65 -0
- package/api-docs/classes/VideoRenderer.html +145 -0
- package/api-docs/enums/BroadPhaseMethods.html +3 -0
- package/api-docs/enums/ButtonType.html +3 -0
- package/api-docs/enums/CollisionMethods.html +3 -0
- package/api-docs/enums/RigidBodyType.html +4 -0
- package/api-docs/enums/TextOrientation.html +5 -0
- package/api-docs/enums/TilemapOrientation.html +5 -0
- package/api-docs/functions/between.html +5 -0
- package/api-docs/functions/clamp.html +5 -0
- package/api-docs/functions/fixedRound.html +4 -0
- package/api-docs/functions/randomFloat.html +4 -0
- package/api-docs/functions/randomInt.html +4 -0
- package/api-docs/functions/range.html +5 -0
- package/api-docs/index.html +37 -0
- package/api-docs/interfaces/AnimationConfig.html +10 -0
- package/api-docs/interfaces/AnimatorOptions.html +6 -0
- package/api-docs/interfaces/AudioPlayerOptions.html +8 -0
- package/api-docs/interfaces/BallColliderOptions.html +16 -0
- package/api-docs/interfaces/BoxColliderOptions.html +20 -0
- package/api-docs/interfaces/ButtonOptions.html +16 -0
- package/api-docs/interfaces/ColliderComponent.html +14 -0
- package/api-docs/interfaces/CollisionData.html +10 -0
- package/api-docs/interfaces/EdgeColliderOptions.html +18 -0
- package/api-docs/interfaces/GameConfig.html +28 -0
- package/api-docs/interfaces/IAssetManager.html +40 -0
- package/api-docs/interfaces/ICollider.html +11 -0
- package/api-docs/interfaces/ICollision.html +4 -0
- package/api-docs/interfaces/ICollisionResolution.html +4 -0
- package/api-docs/interfaces/IDomManager.html +6 -0
- package/api-docs/interfaces/IGameObjectManager.html +49 -0
- package/api-docs/interfaces/IInputManager.html +12 -0
- package/api-docs/interfaces/IPhysicsManager.html +8 -0
- package/api-docs/interfaces/IRenderManager.html +7 -0
- package/api-docs/interfaces/ISceneManager.html +18 -0
- package/api-docs/interfaces/ITimeManager.html +16 -0
- package/api-docs/interfaces/MaskRendererOptions.html +18 -0
- package/api-docs/interfaces/PolygonColliderOptions.html +18 -0
- package/api-docs/interfaces/RigidBodyOptions.html +17 -0
- package/api-docs/interfaces/Slice.html +5 -0
- package/api-docs/interfaces/SpriteConfig.html +10 -0
- package/api-docs/interfaces/SpriteRendererOptions.html +32 -0
- package/api-docs/interfaces/TextRendererOptions.html +38 -0
- package/api-docs/interfaces/TiledChunk.html +7 -0
- package/api-docs/interfaces/TiledLayer.html +17 -0
- package/api-docs/interfaces/TiledTilemap.html +9 -0
- package/api-docs/interfaces/TiledTilemapRendererOptions.html +18 -0
- package/api-docs/interfaces/TilemapColliderOptions.html +12 -0
- package/api-docs/interfaces/TilemapRendererOptions.html +22 -0
- package/api-docs/interfaces/Tileset.html +13 -0
- package/api-docs/interfaces/TouchInteraction.html +6 -0
- package/api-docs/interfaces/VideoRendererOptions.html +34 -0
- package/api-docs/modules.html +85 -0
- package/api-docs/types/CollisionMatrix.html +1 -0
- package/lib/component/Animator.d.ts +114 -8
- package/lib/component/AudioPlayer.d.ts +44 -6
- package/lib/component/Button.d.ts +82 -7
- package/lib/component/Camera.d.ts +27 -0
- package/lib/component/RigidBody.d.ts +75 -0
- package/lib/component/Transform.d.ts +35 -0
- package/lib/component/collider/BallCollider.d.ts +48 -0
- package/lib/component/collider/BoxCollider.d.ts +57 -0
- package/lib/component/collider/Collider.d.ts +51 -3
- package/lib/component/collider/EdgeCollider.d.ts +52 -0
- package/lib/component/collider/PolygonCollider.d.ts +53 -0
- package/lib/component/collider/TilemapCollider.d.ts +42 -0
- package/lib/component/rendering/MaskRenderer.d.ts +56 -0
- package/lib/component/rendering/Sprite.d.ts +61 -0
- package/lib/component/rendering/SpriteRenderer.d.ts +92 -2
- package/lib/component/rendering/TextRenderer.d.ts +103 -4
- package/lib/component/rendering/TiledTilemapRenderer.d.ts +114 -6
- package/lib/component/rendering/TilemapRenderer.d.ts +123 -7
- package/lib/component/rendering/VideoRenderer.d.ts +91 -1
- package/lib/core/Component.d.ts +118 -0
- package/lib/core/Game.d.ts +47 -2
- package/lib/core/GameActor.d.ts +20 -4
- package/lib/core/GameConfig.d.ts +45 -2
- package/lib/core/GameObject.d.ts +63 -0
- package/lib/core/Scene.d.ts +32 -0
- package/lib/core/ioc/Config.d.ts +2 -1
- package/lib/core/managers/AssetManager.d.ts +68 -6
- package/lib/core/managers/DomManager.d.ts +11 -0
- package/lib/core/managers/GameObjectManager.d.ts +81 -0
- package/lib/core/managers/HeadlessIterationManager.d.ts +1 -0
- package/lib/core/managers/IterationManager.d.ts +4 -0
- package/lib/core/managers/SceneManager.d.ts +29 -1
- package/lib/core/managers/TimeManager.d.ts +37 -2
- package/lib/gameObject/GameCamera.d.ts +22 -0
- package/lib/gameObject/SpacePointer.d.ts +7 -0
- package/lib/index.cjs.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/input/GamepadController.d.ts +176 -2
- package/lib/input/InputManager.d.ts +18 -0
- package/lib/input/KeyboardController.d.ts +70 -1
- package/lib/input/MouseController.d.ts +35 -0
- package/lib/input/TouchController.d.ts +36 -4
- package/lib/utils/Container.d.ts +1 -0
- package/lib/utils/Exception.d.ts +1 -0
- package/package.json +10 -6
- package/typedoc.json +13 -0
package/lib/core/GameObject.d.ts
CHANGED
|
@@ -4,28 +4,87 @@ import { RigidBody } from "../component/RigidBody";
|
|
|
4
4
|
import { Scene } from "./Scene";
|
|
5
5
|
import { GameActor, InitOptions } from "./GameActor";
|
|
6
6
|
import { Container } from "../utils/Container";
|
|
7
|
+
/** @private */
|
|
7
8
|
export declare const LAYER_DEFAULT = "Default";
|
|
9
|
+
/** @private */
|
|
8
10
|
export type GameObjectClass<T extends GameObject = GameObject> = new (container: Container, id: number, name?: string, parent?: GameObject) => T;
|
|
11
|
+
/**
|
|
12
|
+
* Base class for all objects in the scene.
|
|
13
|
+
* @public
|
|
14
|
+
* @category Core
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* class Player extends GameObject {
|
|
18
|
+
* init(options) {
|
|
19
|
+
* this.tag = "Tag";
|
|
20
|
+
* this.layer = "Default";
|
|
21
|
+
* }
|
|
22
|
+
* start() {
|
|
23
|
+
* // executed in the first available frame
|
|
24
|
+
* }
|
|
25
|
+
* update() {
|
|
26
|
+
* // executed on every frame
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* class Player extends GameObject {
|
|
33
|
+
* protected init(options?: InitOptions): void {
|
|
34
|
+
* this.tag = "Tag";
|
|
35
|
+
* this.layer = "Default";
|
|
36
|
+
* }
|
|
37
|
+
* protected start(): void {
|
|
38
|
+
* // executed in the first available frame
|
|
39
|
+
* }
|
|
40
|
+
* protected update(): void {
|
|
41
|
+
* // executed on every frame
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
9
46
|
export declare class GameObject extends GameActor {
|
|
47
|
+
/** Id automatically assigned at the time of instantiation. */
|
|
10
48
|
readonly id: number;
|
|
49
|
+
/** Name given manually at the time of instantiation. */
|
|
11
50
|
readonly name: string;
|
|
51
|
+
/** Tag used to group objects and optimize their retrieval. */
|
|
12
52
|
tag: string;
|
|
53
|
+
/** Layer used for rendering and physics. Default value is "Default". */
|
|
13
54
|
layer: string;
|
|
55
|
+
/** TRUE for UI objects. Default value is FALSE. Renders the object outside the game world coordinates. */
|
|
14
56
|
ui: boolean;
|
|
57
|
+
/** TRUE to prevent the object from being automatically destroyed when changing the scene. Default value is FALSE. */
|
|
15
58
|
keep: boolean;
|
|
59
|
+
/** @private */
|
|
16
60
|
private _parent;
|
|
61
|
+
/** @private */
|
|
17
62
|
private _active;
|
|
63
|
+
/** @private */
|
|
18
64
|
private components;
|
|
65
|
+
/** @private */
|
|
19
66
|
private activeComponentsCache;
|
|
67
|
+
/** @private */
|
|
20
68
|
private activeChildrenCache;
|
|
69
|
+
/** @private */
|
|
21
70
|
constructor(container: Container, id: number, name?: string, parent?: GameObject);
|
|
71
|
+
/** TRUE for enabled object, FALSE for disabled object. */
|
|
22
72
|
get active(): boolean;
|
|
73
|
+
/** TRUE for enabled object, FALSE for disabled object. */
|
|
23
74
|
set active(active: boolean);
|
|
75
|
+
/** Parent game object. A child object depends on the parent's Transform. */
|
|
24
76
|
get parent(): GameObject | null;
|
|
77
|
+
/** Parent game object. A child object depends on the parent's Transform. */
|
|
25
78
|
set parent(parent: GameObject | null);
|
|
79
|
+
/** @private */
|
|
26
80
|
private updateComponentsActiveStatus;
|
|
81
|
+
/** @private */
|
|
27
82
|
private updateChildrenActiveStatus;
|
|
83
|
+
/**
|
|
84
|
+
* Transform component added natively in the object
|
|
85
|
+
*/
|
|
28
86
|
get transform(): Transform;
|
|
87
|
+
/** RigidBody Component (if any) */
|
|
29
88
|
get rigidBody(): RigidBody;
|
|
30
89
|
/**
|
|
31
90
|
* This method is called when the active state changes.
|
|
@@ -63,6 +122,7 @@ export declare class GameObject extends GameActor {
|
|
|
63
122
|
* @returns The added component
|
|
64
123
|
*/
|
|
65
124
|
addComponent<ComponentType extends Component = Component, OptionsType extends InitOptions = InitOptions>(componentClass: ComponentClass<ComponentType>, options: OptionsType, name: string): ComponentType;
|
|
125
|
+
/** @private */
|
|
66
126
|
private checkMultipleComponent;
|
|
67
127
|
/**
|
|
68
128
|
* Returns all the components in the game object.
|
|
@@ -127,7 +187,10 @@ export declare class GameObject extends GameActor {
|
|
|
127
187
|
* Destroy all the children game objects
|
|
128
188
|
*/
|
|
129
189
|
destroyChildren(): void;
|
|
190
|
+
/** @private */
|
|
130
191
|
protected _destroy(): void;
|
|
192
|
+
/** @private */
|
|
131
193
|
private destroyComponents;
|
|
194
|
+
/** @private */
|
|
132
195
|
protected _stopGame(): void;
|
|
133
196
|
}
|
package/lib/core/Scene.d.ts
CHANGED
|
@@ -2,12 +2,44 @@ import { GameCamera } from "../gameObject/GameCamera";
|
|
|
2
2
|
import { Container } from "../utils/Container";
|
|
3
3
|
import { Game } from "./Game";
|
|
4
4
|
import { GameActor } from "./GameActor";
|
|
5
|
+
/** @private */
|
|
5
6
|
export type SceneClass = new (container: Container, name: string, game: Game) => Scene;
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all game scenes
|
|
9
|
+
* @public
|
|
10
|
+
* @category Core
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* class GameScene extends Scene {
|
|
14
|
+
* init(options) {
|
|
15
|
+
* this.addGameObject(Player);
|
|
16
|
+
* }
|
|
17
|
+
* start() {}
|
|
18
|
+
* update() {}
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* class GameScene extends Scene {
|
|
24
|
+
* protected init(options?: InitOptions): void {
|
|
25
|
+
* this.addGameObject(Player);
|
|
26
|
+
* }
|
|
27
|
+
* protected start(): void {}
|
|
28
|
+
* protected update(): void {}
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
6
32
|
export declare class Scene extends GameActor {
|
|
7
33
|
readonly name: string;
|
|
8
34
|
readonly game: Game;
|
|
35
|
+
/** @private */
|
|
9
36
|
constructor(container: Container, name: string, game: Game);
|
|
37
|
+
/**
|
|
38
|
+
* The main active camera
|
|
39
|
+
*/
|
|
10
40
|
get gameCamera(): GameCamera;
|
|
41
|
+
/** @private */
|
|
11
42
|
protected _destroy(): void;
|
|
43
|
+
/** @private */
|
|
12
44
|
protected _stopGame(): void;
|
|
13
45
|
}
|
package/lib/core/ioc/Config.d.ts
CHANGED
|
@@ -1,21 +1,83 @@
|
|
|
1
1
|
import { IRenderManager } from "angry-pixel-2d-renderer";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Manages the asset loading (images, fonts, audios, videos).
|
|
4
|
+
* @public
|
|
5
|
+
* @category Managers
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* this.assetManager.loadImage("image.png");
|
|
9
|
+
* this.assetManager.loadAudio("audio.ogg");
|
|
10
|
+
* this.assetManager.loadVideo("video.mp4");
|
|
11
|
+
* this.assetManager.loadFont("custom-font", "custom-font.ttf");
|
|
12
|
+
*
|
|
13
|
+
* const imageElement = this.assetManager.getImage("image.png");
|
|
14
|
+
* const audioElement = this.assetManager.getAudio("audio.ogg");
|
|
15
|
+
* const videoElement = this.assetManager.getVideo("video.mp4");
|
|
16
|
+
* const fontFace = this.assetManager.getFont("custom-font");
|
|
17
|
+
*
|
|
18
|
+
* if (this.assetManager.getAssetsLoaded()) {
|
|
19
|
+
* // do something when assets are loaded
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
8
23
|
export interface IAssetManager {
|
|
24
|
+
/**
|
|
25
|
+
* Returns TRUE if the assets are loaded
|
|
26
|
+
* @returns TRUE or FALSE
|
|
27
|
+
*/
|
|
9
28
|
getAssetsLoaded(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Loads an image asset
|
|
31
|
+
* @param url The asset URL
|
|
32
|
+
* @param preloadTexture Creates the texture to be rendered at load time [optional]
|
|
33
|
+
* @returns The HTML Image element created
|
|
34
|
+
*/
|
|
10
35
|
loadImage(url: string, preloadTexture?: boolean): HTMLImageElement;
|
|
36
|
+
/**
|
|
37
|
+
* Loads an audio asset
|
|
38
|
+
* @param url The asset URL
|
|
39
|
+
* @returns The HTML Audio element created
|
|
40
|
+
*/
|
|
11
41
|
loadAudio(url: string): HTMLAudioElement;
|
|
42
|
+
/**
|
|
43
|
+
* Loads a font asset
|
|
44
|
+
* @param family The font family name
|
|
45
|
+
* @param url The asset URL
|
|
46
|
+
* @returns The FontFace object created
|
|
47
|
+
*/
|
|
12
48
|
loadFont(family: string, url: string): FontFace;
|
|
49
|
+
/**
|
|
50
|
+
* Loads an video asset
|
|
51
|
+
* @param url The asset URL
|
|
52
|
+
* @returns The HTML Video element created
|
|
53
|
+
*/
|
|
13
54
|
loadVideo(url: string): HTMLVideoElement;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves an image asset
|
|
57
|
+
* @param url The asset URL
|
|
58
|
+
* @returns The HTML Image element
|
|
59
|
+
*/
|
|
14
60
|
getImage(url: string): HTMLImageElement;
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves an audio asset
|
|
63
|
+
* @param url The asset URL
|
|
64
|
+
* @returns The HTML Audio element
|
|
65
|
+
*/
|
|
15
66
|
getAudio(url: string): HTMLAudioElement;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves a font asset
|
|
69
|
+
* @param url The asset URL
|
|
70
|
+
* @returns The Font element
|
|
71
|
+
*/
|
|
16
72
|
getFont(family: string): FontFace;
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves a video asset
|
|
75
|
+
* @param url The asset URL
|
|
76
|
+
* @returns The HTML Video element
|
|
77
|
+
*/
|
|
17
78
|
getVideo(url: string): HTMLVideoElement;
|
|
18
79
|
}
|
|
80
|
+
/** @private */
|
|
19
81
|
export declare class AssetManager implements IAssetManager {
|
|
20
82
|
private readonly renderManager;
|
|
21
83
|
private readonly assets;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the canvas element
|
|
3
|
+
* @public
|
|
4
|
+
* @category Managers
|
|
5
|
+
* @example
|
|
6
|
+
* ```js
|
|
7
|
+
* const canvasElement = this.domManager.canvas;
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
1
10
|
export interface IDomManager {
|
|
11
|
+
/** The canvas element where the game is rendered */
|
|
2
12
|
canvas: HTMLCanvasElement;
|
|
3
13
|
}
|
|
14
|
+
/** @private */
|
|
4
15
|
export declare class DomManager implements IDomManager {
|
|
5
16
|
private gameWidth;
|
|
6
17
|
private gameHeight;
|
|
@@ -1,21 +1,102 @@
|
|
|
1
1
|
import { GameObject, GameObjectClass } from "../GameObject";
|
|
2
2
|
import { InitOptions } from "../GameActor";
|
|
3
3
|
import { Container } from "../../utils/Container";
|
|
4
|
+
/**
|
|
5
|
+
* Used to create, retrieve and destroy GameObject instances.
|
|
6
|
+
* @public
|
|
7
|
+
* @category Managers
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* // create a new game object instance
|
|
11
|
+
* this.gameObjectManager.addGameObject(Player);
|
|
12
|
+
*
|
|
13
|
+
* // find a game object by its class
|
|
14
|
+
* const player = this.gameObjectManager.findGameObject(Player);
|
|
15
|
+
*
|
|
16
|
+
* // find game objects by their class
|
|
17
|
+
* const coins = this.gameObjectManager.findGameObjects(Coin);
|
|
18
|
+
*
|
|
19
|
+
* // find game objects by their tag
|
|
20
|
+
* const enemies = this.gameObjectManager.findGameObjectsByTag("Enemy");
|
|
21
|
+
*
|
|
22
|
+
* // destroy a game object
|
|
23
|
+
* this.gameObjectManager.destroyGameObject(player);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
4
26
|
export interface IGameObjectManager {
|
|
27
|
+
/**
|
|
28
|
+
* Instantiates a new game object.
|
|
29
|
+
* @param gameObjectClass The game object class.
|
|
30
|
+
* @param options [optional] Options for the Init method.
|
|
31
|
+
* @param parent [optional] The parent game object.
|
|
32
|
+
* @param name [optional] The name associated to the game object.
|
|
33
|
+
* @returns The game object instance.
|
|
34
|
+
*/
|
|
5
35
|
addGameObject<T extends GameObject>(gameObjectClass: GameObjectClass<T>, options?: InitOptions, parent?: GameObject, name?: string): T;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a collection of found game objects for the given class, or all the game objects if there is no class.
|
|
38
|
+
* @param gameObjectClass [optional] The game object class to find.
|
|
39
|
+
* @returns The found game objects.
|
|
40
|
+
*/
|
|
6
41
|
findGameObjects<T extends GameObject>(gameObjectClass?: GameObjectClass<T>): T[];
|
|
42
|
+
/**
|
|
43
|
+
* Returns the first game object found for the given id, or undefined otherwise.
|
|
44
|
+
* @param id The game object id to find.
|
|
45
|
+
* @returns The found game object.
|
|
46
|
+
*/
|
|
7
47
|
findGameObjectById<T extends GameObject>(id: number): T;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the first game object found for the given class, or undefined otherwise.
|
|
50
|
+
* @param gameObjectClass The game object class to find.
|
|
51
|
+
* @returns The found game object.
|
|
52
|
+
*/
|
|
8
53
|
findGameObject<T extends GameObject>(gameObjectClass: GameObjectClass<T>): T;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the first game object found for the given name, or undefined otherwise.
|
|
56
|
+
* @param name The name of the game object to find.
|
|
57
|
+
* @returns The found game object.
|
|
58
|
+
*/
|
|
9
59
|
findGameObject<T extends GameObject>(name: string): T;
|
|
10
60
|
findGameObject<T extends GameObject>(filter: GameObjectClass<T> | string): T;
|
|
61
|
+
/**
|
|
62
|
+
* Returns a collection of children game objects for the given parent object.
|
|
63
|
+
* @param parent The parent game object.
|
|
64
|
+
* @returns The found game objects.
|
|
65
|
+
*/
|
|
11
66
|
findGameObjectsByParent<T extends GameObject>(parent: GameObject): T[];
|
|
67
|
+
/**
|
|
68
|
+
* Returns the first child game object for the given parent object and filtered by the given game object class.
|
|
69
|
+
* @param parent The parent game object.
|
|
70
|
+
* @param gameObjectClass The game object class to find.
|
|
71
|
+
* @returns The found game object.
|
|
72
|
+
*/
|
|
12
73
|
findGameObjectByParent<T extends GameObject>(parent: GameObject, gameObjectClass: GameObjectClass<T>): T;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the first child game object for the given parent object and filtered by the given name.
|
|
76
|
+
* @param parent The parent game object.
|
|
77
|
+
* @param name The name of the game object to find.
|
|
78
|
+
* @returns The found game object.
|
|
79
|
+
*/
|
|
13
80
|
findGameObjectByParent<T extends GameObject>(parent: GameObject, name: string): T;
|
|
14
81
|
findGameObjectByParent<T extends GameObject>(parent: GameObject, filter: GameObjectClass<T> | string): T;
|
|
82
|
+
/**
|
|
83
|
+
* Returns a collection of game objects found for the given tag.
|
|
84
|
+
* @param tag The tag of the game objects to find.
|
|
85
|
+
* @returns The found game objects.
|
|
86
|
+
*/
|
|
15
87
|
findGameObjectsByTag<T extends GameObject>(tag: string): T[];
|
|
88
|
+
/**
|
|
89
|
+
* Destroy all game objets.
|
|
90
|
+
* @param ignoreKeep [optional] If TRUE, it also destroys objects with the "keep" property set to TRUE.
|
|
91
|
+
*/
|
|
16
92
|
destroyAllGameObjects(ignoreKeep?: boolean): void;
|
|
93
|
+
/**
|
|
94
|
+
* Destroy the given game object.
|
|
95
|
+
* @param gameObject The game object to destory.
|
|
96
|
+
*/
|
|
17
97
|
destroyGameObject(gameObject: GameObject): void;
|
|
18
98
|
}
|
|
99
|
+
/** @private */
|
|
19
100
|
export declare class GameObjectManager implements IGameObjectManager {
|
|
20
101
|
private readonly container;
|
|
21
102
|
private gameObjects;
|
|
@@ -3,6 +3,7 @@ import { ISceneManager } from "./SceneManager";
|
|
|
3
3
|
import { ITimeManager } from "./TimeManager";
|
|
4
4
|
import { IIterationManager } from "./IterationManager";
|
|
5
5
|
import { IPhysicsManager } from "angry-pixel-2d-physics";
|
|
6
|
+
/** @private */
|
|
6
7
|
export declare class HeadlessIterationManager implements IIterationManager {
|
|
7
8
|
private readonly timeManager;
|
|
8
9
|
private readonly physicsManager;
|
|
@@ -4,6 +4,7 @@ import { IInputManager } from "../../input/InputManager";
|
|
|
4
4
|
import { IRenderManager } from "angry-pixel-2d-renderer";
|
|
5
5
|
import { ITimeManager } from "./TimeManager";
|
|
6
6
|
import { IPhysicsManager } from "angry-pixel-2d-physics";
|
|
7
|
+
/** @private */
|
|
7
8
|
export declare enum FrameEvent {
|
|
8
9
|
Init = 0,
|
|
9
10
|
Start = 1,
|
|
@@ -18,6 +19,7 @@ export declare enum FrameEvent {
|
|
|
18
19
|
Destroy = 10,
|
|
19
20
|
StopGame = 11
|
|
20
21
|
}
|
|
22
|
+
/** @private */
|
|
21
23
|
export interface IIterationManager {
|
|
22
24
|
running: boolean;
|
|
23
25
|
start(): void;
|
|
@@ -25,7 +27,9 @@ export interface IIterationManager {
|
|
|
25
27
|
resume(): void;
|
|
26
28
|
stop(): void;
|
|
27
29
|
}
|
|
30
|
+
/** @private */
|
|
28
31
|
export declare const now: () => number;
|
|
32
|
+
/** @private */
|
|
29
33
|
export declare class IterationManager implements IIterationManager {
|
|
30
34
|
private readonly timeManager;
|
|
31
35
|
private readonly physicsManager;
|
|
@@ -2,15 +2,44 @@ import { Scene, SceneClass } from "../Scene";
|
|
|
2
2
|
import { IRenderManager } from "angry-pixel-2d-renderer";
|
|
3
3
|
import { InitOptions } from "../GameActor";
|
|
4
4
|
import { Container } from "../../utils/Container";
|
|
5
|
+
/**
|
|
6
|
+
* Manges the loading of the scenes.
|
|
7
|
+
* @public
|
|
8
|
+
* @category Managers
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* this.sceneManager.loadScene("MainScene");
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
5
14
|
export interface ISceneManager {
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the current loaded scene.
|
|
17
|
+
* @returns The scene instance.
|
|
18
|
+
*/
|
|
6
19
|
getCurrentScene<T extends Scene>(): T;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a new scene.
|
|
22
|
+
* @param sceneClass The scene class .
|
|
23
|
+
* @param name The name to identify the scene.
|
|
24
|
+
* @param options [optional] Options for the init method.
|
|
25
|
+
* @param openingScene [optional] TRUE if it's the first scene to load.
|
|
26
|
+
*/
|
|
7
27
|
addScene(sceneClass: SceneClass, name: string, options?: InitOptions, openingScene?: boolean): void;
|
|
28
|
+
/** Loads the scene flagged as the opening scene. */
|
|
8
29
|
loadOpeningScene(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Loads a Scene by the given name.
|
|
32
|
+
* @param name The name of the Scene.
|
|
33
|
+
*/
|
|
9
34
|
loadScene(name: string): void;
|
|
35
|
+
/** @private */
|
|
10
36
|
update(): void;
|
|
37
|
+
/** @private */
|
|
11
38
|
unloadCurrentScene(): void;
|
|
39
|
+
/** @private */
|
|
12
40
|
stopGame(): void;
|
|
13
41
|
}
|
|
42
|
+
/** @private */
|
|
14
43
|
export declare class SceneManager implements ISceneManager {
|
|
15
44
|
private readonly container;
|
|
16
45
|
private renderManager?;
|
|
@@ -18,7 +47,6 @@ export declare class SceneManager implements ISceneManager {
|
|
|
18
47
|
private currentScene;
|
|
19
48
|
private openingSceneName;
|
|
20
49
|
private sceneToLoad;
|
|
21
|
-
currentSceneName: string;
|
|
22
50
|
constructor(container: Container, renderManager?: IRenderManager);
|
|
23
51
|
getCurrentScene<T extends Scene>(): T;
|
|
24
52
|
addScene(sceneClass: SceneClass, name: string, options?: InitOptions, openingScene?: boolean): void;
|
|
@@ -1,21 +1,56 @@
|
|
|
1
1
|
export declare const MIN_GAME_FRAMERATE = 30;
|
|
2
2
|
export declare const DEFAULT_GAME_FRAMERATE = 60;
|
|
3
3
|
export declare const DEFAULT_PHYSICS_FRAMERATE = 180;
|
|
4
|
+
/**
|
|
5
|
+
* Manages the properties associated with time.
|
|
6
|
+
* @public
|
|
7
|
+
* @category Managers
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* // using deltaTime to increment a timer
|
|
11
|
+
* this.timer += this.timeManager.deltaTime;
|
|
12
|
+
*
|
|
13
|
+
* // using physicsDeltaTime within a physics component to move the object it belongs to
|
|
14
|
+
* this.transform.position.x += speed * this.timeManager.physicsDeltaTime;
|
|
15
|
+
*
|
|
16
|
+
* // stop all time-related interactions by setting the scale to zero
|
|
17
|
+
* this.timeManager.timeScale = 0;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
4
20
|
export interface ITimeManager {
|
|
21
|
+
/** @private */
|
|
5
22
|
minGameDeltatime: number;
|
|
23
|
+
/** @private */
|
|
6
24
|
minPhysicsDeltaTime: number;
|
|
25
|
+
/** @private */
|
|
7
26
|
gameFramerate: number;
|
|
27
|
+
/** @private */
|
|
8
28
|
physicsFramerate: number;
|
|
29
|
+
/** The time difference, in seconds, between the last frame and the current frame. */
|
|
30
|
+
deltaTime: number;
|
|
31
|
+
/** The time difference, in seconds, between the last physics frame and the current one. */
|
|
32
|
+
physicsDeltaTime: number;
|
|
33
|
+
/**
|
|
34
|
+
* The scale on which time passes. The default value is 1.\
|
|
35
|
+
* For example, if set to 2, the time will run at twice the speed.\
|
|
36
|
+
* If set to 0.5, it will run at half the speed.\
|
|
37
|
+
* If set to 0, everything associated with the time will stop.
|
|
38
|
+
*/
|
|
9
39
|
timeScale: number;
|
|
40
|
+
/** The time difference, in seconds, between the last frame and the current frame, unaffected by the scale. */
|
|
10
41
|
unscaledDeltaTime: number;
|
|
42
|
+
/** The time difference, in seconds, between the last physics frame and the current one, unaffected by the scale. */
|
|
11
43
|
unscaledPhysicsDeltaTime: number;
|
|
12
|
-
|
|
13
|
-
physicsDeltaTime: number;
|
|
44
|
+
/** The time difference, in seconds, between the last frame of and the current frame recorded by the browser. */
|
|
14
45
|
browserDeltaTime: number;
|
|
46
|
+
/** @private */
|
|
15
47
|
updateForGame(time: number): void;
|
|
48
|
+
/** @private */
|
|
16
49
|
updateForBrowser(time: number): void;
|
|
50
|
+
/** @private */
|
|
17
51
|
updateForPhysics(time: number): void;
|
|
18
52
|
}
|
|
53
|
+
/** @private */
|
|
19
54
|
export declare class TimeManager implements ITimeManager {
|
|
20
55
|
readonly minGameDeltatime: number;
|
|
21
56
|
readonly minPhysicsDeltaTime: number;
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
import { GameObject } from "../core/GameObject";
|
|
2
2
|
import { Camera } from "../component/Camera";
|
|
3
3
|
import { Rectangle } from "angry-pixel-math";
|
|
4
|
+
/**
|
|
5
|
+
* This GameCamera object is automatically added to all scenes, but it also allows
|
|
6
|
+
* new instances of it to be created, for example, to generate parallax effects.
|
|
7
|
+
* @public
|
|
8
|
+
* @category Game Objects
|
|
9
|
+
*/
|
|
4
10
|
export declare class GameCamera extends GameObject {
|
|
11
|
+
/** The Camera component instance */
|
|
5
12
|
camera: Camera;
|
|
6
13
|
protected init(): void;
|
|
14
|
+
/** Layers to be rendered by this camera */
|
|
7
15
|
set layers(layers: string[]);
|
|
16
|
+
/** Layers to be rendered by this camera */
|
|
8
17
|
get layers(): string[];
|
|
18
|
+
/** In case you have more than one camera, the depth value determines which camera is rendered first */
|
|
9
19
|
set depth(depth: number);
|
|
20
|
+
/** In case you have more than one camera, the depth value determines which camera is rendered first */
|
|
10
21
|
get depth(): number;
|
|
22
|
+
/** Camera zoom. Default value is 1 */
|
|
11
23
|
set zoom(zoom: number);
|
|
24
|
+
/** Camera zoom. Default value is 1 */
|
|
12
25
|
get zoom(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Rectangle representing the field of view of the camera in the game world
|
|
28
|
+
* @readonly
|
|
29
|
+
*/
|
|
13
30
|
get worldSpaceRect(): Rectangle;
|
|
31
|
+
/**
|
|
32
|
+
* Rectangle representing the field of view of the camera from the perspective of the screen
|
|
33
|
+
* @readonly
|
|
34
|
+
*/
|
|
14
35
|
get viewportRect(): Rectangle;
|
|
36
|
+
/** Adds a new layer to the end of the stack */
|
|
15
37
|
addLayer(layer: string): void;
|
|
16
38
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { GameObject } from "../core/GameObject";
|
|
2
|
+
/**
|
|
3
|
+
* This object can be used to click anywhere in the game and get the coordinates relative to the game world.
|
|
4
|
+
* The coordinates are expressed as an xy vector in the browser console.
|
|
5
|
+
* It is a useful tool to know where to position objects.
|
|
6
|
+
* @public
|
|
7
|
+
* @category Game Objects
|
|
8
|
+
*/
|
|
2
9
|
export declare class SpacePointer extends GameObject {
|
|
3
10
|
private camera;
|
|
4
11
|
private mousePressed;
|