rapid-render 0.1.0 → 0.1.2-1.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 +59 -97
- package/dist/assets.d.ts +92 -0
- package/dist/audio.d.ts +59 -0
- package/dist/depth.d.ts +8 -0
- package/dist/game.d.ts +292 -0
- package/dist/index.d.ts +9 -3
- package/dist/input.d.ts +93 -0
- package/dist/interface.d.ts +337 -32
- package/dist/light.d.ts +7 -0
- package/dist/line.d.ts +15 -2
- package/dist/log.d.ts +2 -0
- package/dist/math.d.ts +272 -45
- package/dist/particle.d.ts +73 -0
- package/dist/rapid.global.js +1 -1
- package/dist/rapid.js +1 -1
- package/dist/rapid.umd.cjs +1 -1
- package/dist/regions/attributes.d.ts +44 -0
- package/dist/regions/graphic_region.d.ts +7 -20
- package/dist/regions/region.d.ts +23 -7
- package/dist/regions/sprite_region.d.ts +5 -26
- package/dist/render.d.ts +159 -45
- package/dist/texture.d.ts +105 -13
- package/dist/tilemap.d.ts +98 -0
- package/dist/utils.d.ts +106 -0
- package/dist/webgl/glshader.d.ts +15 -4
- package/dist/webgl/uniform.d.ts +14 -0
- package/dist/webgl/utils.d.ts +11 -1
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -1,126 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
> [!WARNING]
|
|
2
|
+
> **🚧 Major Refactoring in Progress 🚧**
|
|
3
|
+
>
|
|
4
|
+
> This project is currently undergoing a significant rewrite to improve its core architecture and introduce new features. As a result, the **current documentation and examples are outdated** and may not work with the `main` branch.
|
|
5
|
+
>
|
|
6
|
+
> We are working hard to update the documentation soon. Thank you for your patience!
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
# Rapid.js
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
A highly efficient ([stress-test](https://nightre.github.io/Rapid.js/docs/examples.html)) and lightweight WebGL-based 2D rendering engine focused on rendering capabilities.
|
|
6
11
|
|
|
7
|
-
[
|
|
12
|
+
### [Website](https://nightre.github.io/Rapid.js/docs/index.html)
|
|
8
13
|
|
|
9
|
-
[
|
|
14
|
+
#### [Document](https://nightre.github.io/Rapid.js/docs/docs.html) | [API Docs](https://nightre.github.io/Rapid.js/docs/api/index.html) | [Examples](https://nightre.github.io/Rapid.js/docs/examples.html)
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
## Features
|
|
12
17
|
|
|
18
|
+
* **Fast Rendering** ⚡
|
|
19
|
+
* **TileMap** - YSort, isometric 🗺️
|
|
20
|
+
* **Light Shadow** 💡
|
|
21
|
+
* **Particle** 🎆
|
|
22
|
+
* **Camera** 🎥
|
|
23
|
+
* **Graphics Drawing** ✏️
|
|
24
|
+
* **Text Rendering** 📝
|
|
25
|
+
* **Line Drawing** - line texture 〰️
|
|
26
|
+
* **Custom Shaders** 🎨
|
|
27
|
+
* **Mask** 🎭
|
|
28
|
+
* **Frame Buffer Object** 🖼️
|
|
13
29
|
|
|
30
|
+
## Performance Testing
|
|
14
31
|
|
|
15
|
-
|
|
16
|
-
* **Fast Rendering**: Render 10,000 sprites at 60fps
|
|
17
|
-
* **Multi-Texture Support**: Batch rendering using GPU's maximum texture units
|
|
18
|
-
* **Graphics Drawing**
|
|
19
|
-
* **Matrix Stack**
|
|
20
|
-
* **Text Rendering**
|
|
21
|
-
* **Line Drawing**
|
|
22
|
-
* **Custom Shaders**
|
|
23
|
-
* **Texture Clipping**
|
|
32
|
+
32x32 Texture Sprites 60FPS
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
* `Intel® Iris® Xe Graphics` : 42K sprites
|
|
26
35
|
|
|
27
|
-
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
28
39
|
npm i rapid-render
|
|
29
40
|
```
|
|
30
41
|
|
|
31
|
-
Or
|
|
42
|
+
Or via CDN:
|
|
32
43
|
|
|
33
44
|
```html
|
|
34
45
|
<script src="https://unpkg.com/rapid-render/dist/rapid.umd.cjs"></script>
|
|
35
46
|
```
|
|
36
47
|
|
|
37
|
-
|
|
48
|
+
## Quick Start
|
|
38
49
|
|
|
39
50
|
```js
|
|
40
|
-
import { Rapid } from "rapid-render"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
rapid.startRender();
|
|
58
|
-
|
|
59
|
-
// Render here...
|
|
60
|
-
|
|
61
|
-
// Call after rendering
|
|
62
|
-
rapid.endRender();
|
|
63
|
-
|
|
64
|
-
// Set canvas size
|
|
65
|
-
rapid.resize(100, 100);
|
|
51
|
+
import { Rapid, Color, Vec2 } from "rapid-render"
|
|
52
|
+
|
|
53
|
+
// Initialize
|
|
54
|
+
const rapid = new Rapid({
|
|
55
|
+
canvas: document.getElementById("gameCanvas"),
|
|
56
|
+
backgroundColor: Color.fromHex("E6F0FF")
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Render example
|
|
60
|
+
rapid.render(() => {
|
|
61
|
+
rapid.renderRect({
|
|
62
|
+
offset: new Vec2(100, 100),
|
|
63
|
+
width: 50,
|
|
64
|
+
height: 50,
|
|
65
|
+
color: Color.Red
|
|
66
|
+
})
|
|
67
|
+
})
|
|
66
68
|
```
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
For more examples and detailed documentation, visit our [website](https://nightre.github.io/Rapid.js/docs/index.html).
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
const text = rapid.textures.createText({ text: "Hello!", fontSize: 30 })
|
|
72
|
+
## Roadmap
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
rapid.matrixStack.scale(1)
|
|
76
|
-
rapid.matrixStack.rotate(0)
|
|
74
|
+
* 9-slice 🚧 (In Progress)
|
|
75
|
+
* Nodejs Support
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
rapid.renderSprite(cat, 0, 0, color) // or rapid.renderSprite(cat, 0, 0, { color })
|
|
77
|
+
## Contributing
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
const path = Vec2.FormArray([[0, 0], [100, 0], [100, 100]])
|
|
83
|
-
rapid.renderGraphic(0,0,{points:path, color:green})
|
|
84
|
-
// or
|
|
85
|
-
// rapid.startGraphicDraw()
|
|
86
|
-
// rapid.addGraphicVertex(0, 0, color)
|
|
87
|
-
// rapid.endGraphicDraw()
|
|
79
|
+
Issues and PRs are welcome!
|
|
88
80
|
|
|
89
|
-
|
|
90
|
-
rapid.renderSprite(text, 200, 0)
|
|
91
|
-
text.setText("time:" + Math.round(time))
|
|
92
|
-
|
|
93
|
-
rapid.restore() // back to the previous saved state
|
|
94
|
-
```
|
|
81
|
+
## Screen shot
|
|
95
82
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const vertexShaderSource = `...`
|
|
102
|
-
const fragmentShaderSource = `...`
|
|
103
|
-
|
|
104
|
-
const customShader = new GLShader(rapid, vertexShaderSource, fragmentShaderSource)
|
|
105
|
-
rapid.startRender()
|
|
106
|
-
|
|
107
|
-
rapid.renderSprite(plane, 100, 100, {
|
|
108
|
-
shader: customShader, // shader
|
|
109
|
-
uniforms: {
|
|
110
|
-
// Set custom uniform (You can set mat3, vec2, and so on here)
|
|
111
|
-
uCustomUniform: Number(costumUniformValue)
|
|
112
|
-
// uVec2Uniform: [0,2] // recognized as vec2
|
|
113
|
-
// uMat3Uniform: [
|
|
114
|
-
// [0,0,0],
|
|
115
|
-
// [0,0,0],
|
|
116
|
-
// [0,0,0],
|
|
117
|
-
// ]
|
|
118
|
-
// recognized as mat3
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
rapid.endRender()
|
|
123
|
-
```
|
|
124
|
-
# Screen Shot
|
|
83
|
+

|
|
84
|
+

|
|
85
|
+

|
|
86
|
+

|
|
87
|
+

|
|
125
88
|
|
|
126
|
-

|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AudioPlayer } from "./audio";
|
|
2
|
+
import { Game } from "./game";
|
|
3
|
+
import { IAsset as IAsset, IAssets } from "./interface";
|
|
4
|
+
import EventEmitter from "eventemitter3";
|
|
5
|
+
/**
|
|
6
|
+
* Events emitted by AssetsLoader.
|
|
7
|
+
*/
|
|
8
|
+
interface AssetsLoaderEvents {
|
|
9
|
+
progress: (progress: number, loaded: number, total: number) => void;
|
|
10
|
+
complete: (assets: IAssets) => void;
|
|
11
|
+
error: (error: {
|
|
12
|
+
name: string;
|
|
13
|
+
url: string;
|
|
14
|
+
error: any;
|
|
15
|
+
}) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* AssetsLoader class for loading game assets (JSON, audio, images).
|
|
19
|
+
* Supports asynchronous loading with progress tracking and error handling.
|
|
20
|
+
*/
|
|
21
|
+
declare class AssetsLoader extends EventEmitter<AssetsLoaderEvents> {
|
|
22
|
+
private assets;
|
|
23
|
+
private totalAsset;
|
|
24
|
+
private loadedAssets;
|
|
25
|
+
private game;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of AssetsLoader.
|
|
28
|
+
* Initializes the asset storage and counters.
|
|
29
|
+
*/
|
|
30
|
+
constructor(game: Game);
|
|
31
|
+
/**
|
|
32
|
+
* Loads a JSON file asynchronously.
|
|
33
|
+
* @param name - The unique identifier for the JSON asset.
|
|
34
|
+
* @param url - The URL of the JSON file.
|
|
35
|
+
*/
|
|
36
|
+
loadJson(name: string, url: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Loads an audio file asynchronously.
|
|
39
|
+
* @param name - The unique identifier for the audio asset.
|
|
40
|
+
* @param url - The URL of the audio file.
|
|
41
|
+
*/
|
|
42
|
+
loadAudio(name: string, url: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Loads an image file asynchronously.
|
|
45
|
+
* @param name - The unique identifier for the image asset.
|
|
46
|
+
* @param url - The URL of the image file.
|
|
47
|
+
*/
|
|
48
|
+
loadImage(name: string, url: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Loads multiple assets from a list.
|
|
51
|
+
* @param assetList - Array of assets to load.
|
|
52
|
+
*/
|
|
53
|
+
loadAssets(assetList: IAsset[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* Handles the completion of an asset load.
|
|
56
|
+
* Updates progress and triggers completion event if all assets are loaded.
|
|
57
|
+
*/
|
|
58
|
+
private assetLoaded;
|
|
59
|
+
/**
|
|
60
|
+
* Handles errors during asset loading.
|
|
61
|
+
* @param name - The name of the asset.
|
|
62
|
+
* @param url - The URL of the asset.
|
|
63
|
+
* @param error - The error object or message.
|
|
64
|
+
*/
|
|
65
|
+
private handleError;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves a loaded asset by type and name.
|
|
68
|
+
* @param type - The type of asset ('json', 'audio', or 'images').
|
|
69
|
+
* @param name - The name of the asset.
|
|
70
|
+
* @returns The loaded asset or undefined if not found.
|
|
71
|
+
*/
|
|
72
|
+
get<T extends keyof IAssets>(type: T, name: string): IAssets[T][string] | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves a loaded JSON asset by name.
|
|
75
|
+
* @param name - The name of the JSON asset.
|
|
76
|
+
* @returns The loaded JSON data or undefined if not found.
|
|
77
|
+
*/
|
|
78
|
+
getJSON(name: string): any | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves a loaded audio asset by name.
|
|
81
|
+
* @param name - The name of the audio asset.
|
|
82
|
+
* @returns The loaded AudioPlayer instance or undefined if not found.
|
|
83
|
+
*/
|
|
84
|
+
getAudio(name: string): AudioPlayer | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a loaded texture (image) asset by name.
|
|
87
|
+
* @param name - The name of the texture asset.
|
|
88
|
+
* @returns The loaded texture or undefined if not found.
|
|
89
|
+
*/
|
|
90
|
+
getTexture(name: string): any | undefined;
|
|
91
|
+
}
|
|
92
|
+
export default AssetsLoader;
|
package/dist/audio.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
|
+
/**
|
|
3
|
+
* Events emitted by AudioPlayer.
|
|
4
|
+
*/
|
|
5
|
+
interface AudioPlayerEvents {
|
|
6
|
+
ended: () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Audio class for managing individual audio elements.
|
|
10
|
+
* Encapsulates an HTMLAudioElement and its Web Audio API nodes.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AudioPlayer extends EventEmitter<AudioPlayerEvents> {
|
|
13
|
+
element: HTMLAudioElement;
|
|
14
|
+
source: AudioNode | null;
|
|
15
|
+
gainNode: GainNode;
|
|
16
|
+
private audioContext;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of Audio.
|
|
19
|
+
* @param audioElement - The HTMLAudioElement to manage.
|
|
20
|
+
* @param audioContext - The Web Audio API context.
|
|
21
|
+
*/
|
|
22
|
+
constructor(audioElement: HTMLAudioElement, audioContext: AudioContext);
|
|
23
|
+
/**
|
|
24
|
+
* Handles the 'ended' event when audio playback completes.
|
|
25
|
+
*/
|
|
26
|
+
private handleEnded;
|
|
27
|
+
/**
|
|
28
|
+
* Plays the audio with optional looping.
|
|
29
|
+
* @param loop - Whether the audio should loop (default: false).
|
|
30
|
+
*/
|
|
31
|
+
play(loop?: boolean): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Pauses the audio.
|
|
34
|
+
*/
|
|
35
|
+
pause(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Stops the audio and resets playback position.
|
|
38
|
+
*/
|
|
39
|
+
stop(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Sets the volume for the audio.
|
|
42
|
+
* @param volume - Volume level (0.0 to 1.0).
|
|
43
|
+
*/
|
|
44
|
+
setVolume(volume: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Cleans up resources associated with the audio.
|
|
47
|
+
*/
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* AudioManager class for managing game audio, including background music (BGM) and sound effects (SFX).
|
|
52
|
+
* Delegates audio-specific responsibilities to AudioPlayer instances.
|
|
53
|
+
*/
|
|
54
|
+
declare class AudioManager {
|
|
55
|
+
audioContext: AudioContext;
|
|
56
|
+
constructor();
|
|
57
|
+
destroy(): void;
|
|
58
|
+
}
|
|
59
|
+
export default AudioManager;
|
package/dist/depth.d.ts
ADDED
package/dist/game.d.ts
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import AssetsLoader from "./assets";
|
|
2
|
+
import AudioManager from "./audio";
|
|
3
|
+
import { InputManager } from "./input";
|
|
4
|
+
import { IEntityTilemapLayerOptions, IEntityTransformOptions, IGameOptions, IMathObject, ISpriteRenderOptions, TilemapShape, YSortCallback } from "./interface";
|
|
5
|
+
import { MatrixStack, Vec2 } from "./math";
|
|
6
|
+
import Rapid from "./render";
|
|
7
|
+
import { TextureCache } from "./texture";
|
|
8
|
+
import { TileSet } from "./tilemap";
|
|
9
|
+
import { EasingFunction, Timer, Tween } from "./utils";
|
|
10
|
+
/**
|
|
11
|
+
* Base class for game entities with transform and rendering capabilities.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Entity {
|
|
14
|
+
position: Vec2;
|
|
15
|
+
scale: Vec2;
|
|
16
|
+
rotation: number;
|
|
17
|
+
parent: Entity | null;
|
|
18
|
+
globalZindex: number;
|
|
19
|
+
localZindex: number;
|
|
20
|
+
tags: string[];
|
|
21
|
+
transform: MatrixStack;
|
|
22
|
+
readonly children: Entity[];
|
|
23
|
+
protected rapid: Rapid;
|
|
24
|
+
protected game: Game;
|
|
25
|
+
get x(): number;
|
|
26
|
+
get y(): number;
|
|
27
|
+
set x(nx: number);
|
|
28
|
+
set y(ny: number);
|
|
29
|
+
/**
|
|
30
|
+
* Creates an entity with optional transform properties.
|
|
31
|
+
* @param game - The game instance this entity belongs to.
|
|
32
|
+
* @param options - Configuration options for position, scale, rotation, and tags.
|
|
33
|
+
*/
|
|
34
|
+
constructor(game: Game, options?: IEntityTransformOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Gets the parent transform or the renderer's matrix stack if no parent exists.
|
|
37
|
+
* @returns The transform matrix stack.
|
|
38
|
+
*/
|
|
39
|
+
getParentTransform(): MatrixStack;
|
|
40
|
+
/**
|
|
41
|
+
* Updates the entity and its children.
|
|
42
|
+
* @param deltaTime - Time elapsed since the last update in seconds.
|
|
43
|
+
*/
|
|
44
|
+
update(deltaTime: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Hook for custom update logic.
|
|
47
|
+
* @param deltaTime - Time elapsed since the last update in seconds.
|
|
48
|
+
*/
|
|
49
|
+
protected onUpdate(deltaTime: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Collects entities that need rendering.
|
|
52
|
+
* @param queue - The array to collect renderable entities.
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
55
|
+
collectRenderables(queue: Entity[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* Prepares the entity's transform before rendering.
|
|
58
|
+
* @ignore
|
|
59
|
+
*/
|
|
60
|
+
beforOnRender(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Hook for custom rendering logic.
|
|
63
|
+
* @param render - The rendering engine instance.
|
|
64
|
+
*/
|
|
65
|
+
onRender(render: Rapid): void;
|
|
66
|
+
/**
|
|
67
|
+
* Updates the entity's transform, optionally updating parent transforms.
|
|
68
|
+
* @param deep - If true, recursively updates parent transforms.
|
|
69
|
+
*/
|
|
70
|
+
updateTransform(deep?: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* Adds a child entity to this entity.
|
|
73
|
+
* @param child - The entity to add as a child.
|
|
74
|
+
*/
|
|
75
|
+
addChild(child: Entity): void;
|
|
76
|
+
/**
|
|
77
|
+
* Removes a child entity from this entity.
|
|
78
|
+
* @param child - The entity to remove.
|
|
79
|
+
*/
|
|
80
|
+
removeChild(child: Entity): void;
|
|
81
|
+
/**
|
|
82
|
+
* Finds descendant entities matching a predicate.
|
|
83
|
+
* @param predicate - Function to test each entity.
|
|
84
|
+
* @param onlyFirst - If true, returns only the first match; otherwise, returns all matches.
|
|
85
|
+
* @returns A single entity, an array of entities, or null if no matches are found.
|
|
86
|
+
*/
|
|
87
|
+
findDescendant(predicate: (entity: Entity) => boolean, onlyFirst?: boolean): Entity[] | Entity | null;
|
|
88
|
+
/**
|
|
89
|
+
* Finds descendant entities with all specified tags.
|
|
90
|
+
* @param tags - Array of tags to match.
|
|
91
|
+
* @param onlyFirst - If true, returns only the first match; otherwise, returns all matches.
|
|
92
|
+
* @returns A single entity, an array of entities, or null if no matches are found.
|
|
93
|
+
*/
|
|
94
|
+
findDescendantByTag(tags: string[], onlyFirst?: boolean): Entity[] | Entity | null;
|
|
95
|
+
/**
|
|
96
|
+
* Disposes of the entity and its children.
|
|
97
|
+
*/
|
|
98
|
+
dispose(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Hook for custom cleanup logic before disposal.
|
|
101
|
+
*/
|
|
102
|
+
protected postDispose(): void;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Camera entity for managing the view transform in the game.
|
|
106
|
+
*/
|
|
107
|
+
export declare class Camera extends Entity {
|
|
108
|
+
/**
|
|
109
|
+
* Updates the camera's transform to center the view and apply transformations.
|
|
110
|
+
*/
|
|
111
|
+
updateTransform(): void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Tilemap entity for rendering tiled maps.
|
|
115
|
+
*/
|
|
116
|
+
export declare class Tilemap extends Entity {
|
|
117
|
+
static readonly DEFAULT_ERROR = 0;
|
|
118
|
+
static readonly EMPTY_TILE = -1;
|
|
119
|
+
error: Vec2;
|
|
120
|
+
shape: TilemapShape;
|
|
121
|
+
tileSet: TileSet;
|
|
122
|
+
data: (number | string)[][];
|
|
123
|
+
eachTile?: (tileId: string | number, mapX: number, mapY: number) => ISpriteRenderOptions | undefined | void;
|
|
124
|
+
ySortCallback: YSortCallback[];
|
|
125
|
+
/**
|
|
126
|
+
* Creates a tilemap entity.
|
|
127
|
+
* @param game - The game instance this tilemap belongs to.
|
|
128
|
+
* @param options - Configuration options for the tilemap.
|
|
129
|
+
*/
|
|
130
|
+
constructor(game: Game, options: IEntityTilemapLayerOptions);
|
|
131
|
+
/**
|
|
132
|
+
* Collects renderable entities, excluding children unless they override onRender.
|
|
133
|
+
* @param queue - The array to collect renderable entities.
|
|
134
|
+
*/
|
|
135
|
+
collectRenderables(queue: Entity[]): void;
|
|
136
|
+
/**
|
|
137
|
+
* Sets a tile at the specified map coordinates.
|
|
138
|
+
* @param x - The X coordinate (column) on the map.
|
|
139
|
+
* @param y - The Y coordinate (row) on the map.
|
|
140
|
+
* @param tileId - The tile ID to set (number or string).
|
|
141
|
+
* @returns True if the tile was set successfully, false if coordinates are out of bounds.
|
|
142
|
+
*/
|
|
143
|
+
setTile(x: number, y: number, tileId: number | string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Gets the tile ID at the specified map coordinates.
|
|
146
|
+
* @param x - The X coordinate (column) on the map.
|
|
147
|
+
* @param y - The Y coordinate (row) on the map.
|
|
148
|
+
* @returns The tile ID (number or string) or undefined if coordinates are out of bounds.
|
|
149
|
+
*/
|
|
150
|
+
getTile(x: number, y: number): number | string | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Removes a tile at the specified map coordinates (sets it to EMPTY_TILE).
|
|
153
|
+
* @param x - The X coordinate (column) on the map.
|
|
154
|
+
* @param y - The Y coordinate (row) on the map.
|
|
155
|
+
* @returns True if the tile was removed successfully, false if coordinates are out of bounds.
|
|
156
|
+
*/
|
|
157
|
+
removeTile(x: number, y: number): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Fills a rectangular area with a specified tile ID.
|
|
160
|
+
* @param tileId - The tile ID to use for filling.
|
|
161
|
+
* @param startX - The starting X coordinate.
|
|
162
|
+
* @param startY - The starting Y coordinate.
|
|
163
|
+
* @param width - The width of the fill area.
|
|
164
|
+
* @param height - The height of the fill area.
|
|
165
|
+
*/
|
|
166
|
+
fill(tileId: number | string, startX: number, startY: number, width: number, height: number): void;
|
|
167
|
+
/**
|
|
168
|
+
* Replaces the entire tilemap data and updates dimensions.
|
|
169
|
+
* @param newData - The new 2D array of tile data.
|
|
170
|
+
*/
|
|
171
|
+
setData(newData: (number | string)[][]): void;
|
|
172
|
+
/**
|
|
173
|
+
* Converts local coordinates to map coordinates.
|
|
174
|
+
* @param local - The local coordinates to convert.
|
|
175
|
+
*/
|
|
176
|
+
localToMap(local: Vec2): void;
|
|
177
|
+
/**
|
|
178
|
+
* Converts map coordinates to local coordinates.
|
|
179
|
+
* @param local - The map coordinates to convert.
|
|
180
|
+
*/
|
|
181
|
+
mapToLocal(local: Vec2): void;
|
|
182
|
+
/**
|
|
183
|
+
* Renders the tilemap layer.
|
|
184
|
+
* @param render - The rendering engine instance.
|
|
185
|
+
*/
|
|
186
|
+
onRender(render: Rapid): void;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Scene class representing a game scene with entities.
|
|
190
|
+
*/
|
|
191
|
+
export declare class Scene extends Entity {
|
|
192
|
+
/**
|
|
193
|
+
* Initializes the scene.
|
|
194
|
+
*/
|
|
195
|
+
create(): void;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Main game class managing the game loop, rendering, and input.
|
|
199
|
+
*/
|
|
200
|
+
export declare class Game {
|
|
201
|
+
render: Rapid;
|
|
202
|
+
mainScene: Scene | null;
|
|
203
|
+
input: InputManager;
|
|
204
|
+
asset: AssetsLoader;
|
|
205
|
+
audio: AudioManager;
|
|
206
|
+
texture: TextureCache;
|
|
207
|
+
private isRunning;
|
|
208
|
+
private lastTime;
|
|
209
|
+
private tweens;
|
|
210
|
+
private timers;
|
|
211
|
+
renderQueue: Entity[];
|
|
212
|
+
/**
|
|
213
|
+
* Creates a new game instance.
|
|
214
|
+
* @param options - Configuration options for the game.
|
|
215
|
+
*/
|
|
216
|
+
constructor(options: IGameOptions);
|
|
217
|
+
/**
|
|
218
|
+
* Switches to a new scene, disposing of the current one.
|
|
219
|
+
* @param newScene - The new scene to switch to.
|
|
220
|
+
*/
|
|
221
|
+
switchScene(newScene: Scene): void;
|
|
222
|
+
/**
|
|
223
|
+
* Starts the game loop.
|
|
224
|
+
*/
|
|
225
|
+
start(): void;
|
|
226
|
+
/**
|
|
227
|
+
* Stops the game loop.
|
|
228
|
+
*/
|
|
229
|
+
stop(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Adds an entity to the render queue.
|
|
232
|
+
* @param entity - The entity to add.
|
|
233
|
+
*/
|
|
234
|
+
addEntityRenderQueue(entity: Entity): void;
|
|
235
|
+
/**
|
|
236
|
+
* Runs the game loop, updating and rendering the scene.
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
private gameLoop;
|
|
240
|
+
destroy(): void;
|
|
241
|
+
/**
|
|
242
|
+
* Creates and starts a new timer that will be automatically updated by the game loop.
|
|
243
|
+
* @param duration - The duration in seconds before the timer triggers.
|
|
244
|
+
* @param onComplete - The function to call when the timer finishes.
|
|
245
|
+
* @param repeat - If true, the timer will restart after completing. Defaults to false.
|
|
246
|
+
* @returns The created Timer instance, allowing you to `stop()` it manually if needed.
|
|
247
|
+
* @example
|
|
248
|
+
* // Log a message after 2.5 seconds
|
|
249
|
+
* game.createTimer(2.5, () => {
|
|
250
|
+
* console.log('Timer finished!');
|
|
251
|
+
* });
|
|
252
|
+
*
|
|
253
|
+
* // Spawn an enemy every 5 seconds
|
|
254
|
+
* const enemySpawner = game.createTimer(5, () => {
|
|
255
|
+
* scene.spawnEnemy();
|
|
256
|
+
* }, true);
|
|
257
|
+
*/
|
|
258
|
+
createTimer(duration: number, repeat?: boolean): Timer;
|
|
259
|
+
/**
|
|
260
|
+
* Updates all active timers and removes completed ones.
|
|
261
|
+
* @param deltaTime - The time elapsed since the last frame.
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
private updateTimers;
|
|
265
|
+
/**
|
|
266
|
+
* Creates and starts a new tween animation.
|
|
267
|
+
* The tween will be automatically updated by the game loop.
|
|
268
|
+
* @template T - The type of the value being animated (e.g., Vec2, Color, number).
|
|
269
|
+
* @param target - The object to animate.
|
|
270
|
+
* @param property - The name of the property on the target to animate.
|
|
271
|
+
* @param to - The final value of the property.
|
|
272
|
+
* @param duration - The duration of the animation in seconds.
|
|
273
|
+
* @param easing - The easing function to use. Defaults to Linear.
|
|
274
|
+
* @returns The created Tween instance, allowing you to chain calls like .onComplete().
|
|
275
|
+
* @example
|
|
276
|
+
* // Tween a sprite's position over 2 seconds
|
|
277
|
+
* game.createTween(mySprite, 'position', new Vec2(500, 300), 2, Easing.EaseOutQuad);
|
|
278
|
+
*
|
|
279
|
+
* // Tween a shape's color to red and do something on completion
|
|
280
|
+
* game.createTween(myShape, 'color', Color.Red, 1.5)
|
|
281
|
+
* .onComplete(() => {
|
|
282
|
+
* console.log('Color tween finished!');
|
|
283
|
+
* });
|
|
284
|
+
*/
|
|
285
|
+
createTween<T extends IMathObject<T> | number>(target: any, property: string, to: T, duration: number, easing?: EasingFunction): Tween<T>;
|
|
286
|
+
/**
|
|
287
|
+
* Updates all active tweens and removes completed ones.
|
|
288
|
+
* @param deltaTime - The time elapsed since the last frame.
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
private updateTweens;
|
|
292
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { graphicAttributes } from "./regions/graphic_region";
|
|
2
|
-
import { spriteAttributes } from "./regions/sprite_region";
|
|
3
1
|
import Rapid from "./render";
|
|
4
2
|
import GLShader from "./webgl/glshader";
|
|
5
3
|
import { Text } from "./texture";
|
|
6
|
-
|
|
4
|
+
import { TileMapRender, TileSet } from "./tilemap";
|
|
5
|
+
import { Uniform } from "./webgl/uniform";
|
|
6
|
+
import { spriteAttributes, graphicAttributes } from "./regions/attributes";
|
|
7
|
+
import { ParticleEmitter } from "./particle";
|
|
8
|
+
export { Text, Rapid, GLShader, TileMapRender, TileSet, Uniform, ParticleEmitter, graphicAttributes, spriteAttributes, };
|
|
7
9
|
export * from "./math";
|
|
8
10
|
export * from "./interface";
|
|
9
11
|
export * from "./texture";
|
|
10
12
|
export * from "./render";
|
|
13
|
+
export * from "./particle";
|
|
14
|
+
export * from "./game";
|
|
15
|
+
export * from "./input";
|
|
16
|
+
export * from "./assets";
|