woofjs-engine 0.2.0 → 0.4.0
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/CHANGELOG.md +13 -0
- package/README.md +16 -106
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/dist/canvas.js +4 -31
- package/dist/collision.js +8 -5
- package/dist/game.js +4 -84
- package/dist/index-1jykaz1m.js +142 -0
- package/dist/index-9mz0qg9d.js +39 -0
- package/dist/index-b9a70qgn.js +34 -0
- package/dist/index-dp75gf4w.js +57 -0
- package/dist/index-f63yb8zf.js +85 -0
- package/dist/index-gypg8d50.js +31 -0
- package/dist/index-w4yvg8ax.js +2568 -0
- package/dist/index.js +134 -239
- package/dist/input.js +4 -33
- package/dist/play.js +304 -0
- package/dist/sound.js +4 -56
- package/dist/store.js +4 -30
- package/dist/types/canvas.d.ts +20 -2
- package/dist/types/collision.d.ts +62 -0
- package/dist/types/game.d.ts +21 -1
- package/dist/types/global.d.ts +4 -0
- package/dist/types/helpers.d.ts +92 -0
- package/dist/types/index.d.ts +23 -12
- package/dist/types/input.d.ts +4 -0
- package/dist/types/play.d.ts +167 -0
- package/dist/types/sound.d.ts +10 -3
- package/dist/types/sprites/custom.d.ts +9 -0
- package/dist/types/sprites/easing.d.ts +9 -0
- package/dist/types/sprites/geometry.d.ts +22 -0
- package/dist/types/sprites/options.d.ts +98 -0
- package/dist/types/sprites/render.d.ts +2 -0
- package/dist/types/sprites/sprite.d.ts +283 -0
- package/dist/types/store.d.ts +4 -0
- package/dist/types/ui.d.ts +65 -0
- package/dist/types/woof.d.ts +395 -0
- package/dist/types/world/audio.d.ts +118 -0
- package/dist/types/world/globals.d.ts +3 -0
- package/dist/types/world/keys.d.ts +2 -0
- package/dist/types/world/options.d.ts +44 -0
- package/dist/types/world/render.d.ts +13 -0
- package/dist/types/world/scheduler.d.ts +65 -0
- package/dist/ui.js +235 -0
- package/dist/woof.global.js +3620 -0
- package/docs/api.json +5439 -0
- package/docs/woof-parity.md +231 -0
- package/package.json +25 -8
- package/docs/architecture.md +0 -37
- package/docs/planning.md +0 -33
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
export { createGame } from
|
|
2
|
-
export type { GameOptions, GameLoop, FrameInfo } from
|
|
3
|
-
export { createSound } from
|
|
4
|
-
export type { SoundOptions, Sound, Playback, PlaybackOptions } from
|
|
5
|
-
export { createStore } from
|
|
6
|
-
export type { Store } from
|
|
7
|
-
export { createCanvas } from
|
|
8
|
-
export type { CanvasOptions, CanvasSurface } from
|
|
9
|
-
export { createKeyboard } from
|
|
10
|
-
export type { KeyboardInput } from
|
|
11
|
-
export { overlaps } from
|
|
12
|
-
export type { Rectangle } from
|
|
1
|
+
export { createGame } from "./game.js";
|
|
2
|
+
export type { GameOptions, GameLoop, FrameInfo } from "./game.js";
|
|
3
|
+
export { createSound } from "./sound.js";
|
|
4
|
+
export type { SoundOptions, Sound, Playback, PlaybackOptions, } from "./sound.js";
|
|
5
|
+
export { createStore } from "./store.js";
|
|
6
|
+
export type { Store } from "./store.js";
|
|
7
|
+
export { createCanvas } from "./canvas.js";
|
|
8
|
+
export type { CanvasOptions, CanvasSurface } from "./canvas.js";
|
|
9
|
+
export { createKeyboard } from "./input.js";
|
|
10
|
+
export type { KeyboardInput } from "./input.js";
|
|
11
|
+
export { overlaps, detectCollision } from "./collision.js";
|
|
12
|
+
export type { Rectangle, Collider, SATCircle, SATPolygon, } from "./collision.js";
|
|
13
|
+
export * from "./helpers.js";
|
|
14
|
+
export { woof, Project } from "./woof.js";
|
|
15
|
+
export type { ProjectOptions } from "./woof.js";
|
|
16
|
+
export { Repeat, RepeatUntil } from "./world/scheduler.js";
|
|
17
|
+
export type { TaskHandle, RepeatHandle, Time } from "./world/scheduler.js";
|
|
18
|
+
export { Sprite } from "./sprites/sprite.js";
|
|
19
|
+
export type { SpriteOptions, SpriteType } from "./sprites/sprite.js";
|
|
20
|
+
export { easings } from "./sprites/easing.js";
|
|
21
|
+
export type { EasingName } from "./sprites/easing.js";
|
|
22
|
+
export { ProjectSound } from "./world/audio.js";
|
|
23
|
+
export type { ProjectSoundOptions } from "./world/audio.js";
|
package/dist/types/input.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/** Observe physical keyboard codes without owning a framework or game loop. */
|
|
2
2
|
export interface KeyboardInput {
|
|
3
|
+
/** Check whether a physical keyboard code is held. Example: `keyboard.isDown('ArrowLeft')`. */
|
|
3
4
|
isDown(code: string): boolean;
|
|
5
|
+
/** Forget all held keys. Example: `keyboard.clear()`. */
|
|
4
6
|
clear(): void;
|
|
7
|
+
/** Remove keyboard listeners and clear held keys. Example: `keyboard.destroy()`. */
|
|
5
8
|
destroy(): void;
|
|
6
9
|
}
|
|
10
|
+
/** Listen for held keyboard codes on an event target. */
|
|
7
11
|
export declare function createKeyboard(target?: EventTarget): KeyboardInput;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type Project } from "./woof.js";
|
|
2
|
+
import type { Sprite as SpriteInstance, SpriteOptions } from "./sprites/sprite.js";
|
|
3
|
+
import type { ProjectSoundOptions } from "./world/audio.js";
|
|
4
|
+
import type { Time, TaskHandle } from "./world/scheduler.js";
|
|
5
|
+
/** Return the lazily created beginner project. */
|
|
6
|
+
export declare function project(): Project;
|
|
7
|
+
/** Mouse x coordinate in the beginner project's world. Example: `player.x = mouseX`. */
|
|
8
|
+
export declare let mouseX: number;
|
|
9
|
+
/** Mouse y coordinate in the beginner project's world. Example: `player.y = mouseY`. */
|
|
10
|
+
export declare let mouseY: number;
|
|
11
|
+
/** Left edge of the visible world. Example: `player.x = minX`. */
|
|
12
|
+
export declare let minX: number;
|
|
13
|
+
/** Right edge of the visible world. Example: `player.x = maxX`. */
|
|
14
|
+
export declare let maxX: number;
|
|
15
|
+
/** Bottom edge of the visible world. Example: `player.y = minY`. */
|
|
16
|
+
export declare let minY: number;
|
|
17
|
+
/** Top edge of the visible world. Example: `player.y = maxY`. */
|
|
18
|
+
export declare let maxY: number;
|
|
19
|
+
type Shape = {
|
|
20
|
+
(options?: SpriteOptions): SpriteInstance;
|
|
21
|
+
/** Construct a sprite from an options object. */
|
|
22
|
+
new (options?: SpriteOptions): SpriteInstance;
|
|
23
|
+
};
|
|
24
|
+
/** Create a circle, for example `new Circle({ radius: 20 })`. */
|
|
25
|
+
export declare const Circle: Shape;
|
|
26
|
+
/** Create a rectangle, for example `new Rectangle({ width: 30, height: 10 })`. */
|
|
27
|
+
export declare const Rectangle: Shape;
|
|
28
|
+
/** Create an oval, for example `new Oval({ width: 20, height: 40 })`. */
|
|
29
|
+
export declare const Oval: Shape;
|
|
30
|
+
/** Create a regular polygon, for example `new Polygon({ sides: 5, length: 20 })`. */
|
|
31
|
+
export declare const Polygon: Shape;
|
|
32
|
+
/** Create a line, for example `new Line({ x1: 30, y1: 20 })`. */
|
|
33
|
+
export declare const Line: Shape;
|
|
34
|
+
/** Create text, for example `new Text({ text: 'Score', size: 24 })`. */
|
|
35
|
+
export declare const Text: Shape;
|
|
36
|
+
/** Create a text primitive. Example: `new TextPrimative({ text: 'Hello' })`. */
|
|
37
|
+
export declare const TextPrimative: Shape;
|
|
38
|
+
/** Create an image sprite, for example `new Image({ url: 'player.png' })`. */
|
|
39
|
+
export declare const Image: Shape;
|
|
40
|
+
/** Group sprites, for example `new Bundle({ components: [player] })`. */
|
|
41
|
+
export declare const Bundle: Shape;
|
|
42
|
+
/** Create a custom sprite, for example `new Sprite({ draw: ctx => ctx.fillRect(0, 0, 10, 10) })`. */
|
|
43
|
+
export declare const Sprite: Shape;
|
|
44
|
+
/** Define a custom sprite constructor. Example: `const Star = customSprite({ render() {} })`. */
|
|
45
|
+
export declare const customSprite: Project["customSprite"];
|
|
46
|
+
/** Create a sound, for example `new Sound({ url: 'sound.mp3' })`. */
|
|
47
|
+
export declare const Sound: {
|
|
48
|
+
(options?: ProjectSoundOptions): ReturnType<Project["sound"]>;
|
|
49
|
+
/** Construct a sound from an options object. */
|
|
50
|
+
new (options?: ProjectSoundOptions): ReturnType<Project["sound"]>;
|
|
51
|
+
};
|
|
52
|
+
/** Run immediately and again at each interval, such as `every(2, 'seconds', fn)`. */
|
|
53
|
+
export declare function every(time: Time, fn: () => void): TaskHandle;
|
|
54
|
+
/** Run immediately and at an interval. Example: `every(2, 'seconds', spawn)`. */
|
|
55
|
+
export declare function every(time: Time, units: string, fn: () => void): TaskHandle;
|
|
56
|
+
/** Run once after a delay, such as `after(2, 'seconds', fn)`. */
|
|
57
|
+
export declare function after(time: Time, fn: () => void): TaskHandle;
|
|
58
|
+
/** Run after a delay. Example: `after(2, 'seconds', spawn)`. */
|
|
59
|
+
export declare function after(time: Time, units: string, fn: () => void): TaskHandle;
|
|
60
|
+
/** Run a callback each frame, for example `forever(() => player.move(1))`. */
|
|
61
|
+
export declare const forever: Project["forever"];
|
|
62
|
+
/** Run each frame while a condition is true, for example `when(() => pressing.includes('UP'), move)`. */
|
|
63
|
+
export declare const when: Project["when"];
|
|
64
|
+
/** Run once when a condition becomes true. */
|
|
65
|
+
export declare const once: Project["once"];
|
|
66
|
+
/** Run once per frame for a count; chain `.then(...)` to run on completion. */
|
|
67
|
+
export declare const repeat: Project["repeat"];
|
|
68
|
+
/** Run once per frame until the condition becomes true. */
|
|
69
|
+
export declare const repeatUntil: Project["repeatUntil"];
|
|
70
|
+
/** Resolve after the specified number of seconds of game time. */
|
|
71
|
+
export declare const wait: (seconds: number) => Promise<void>;
|
|
72
|
+
/** Run after the beginner project is initialized. Example: `ready(startGame)`. */
|
|
73
|
+
export declare const ready: Project["ready"];
|
|
74
|
+
/** Convert world coordinates to canvas coordinates. Example: `translateToCanvas(0, 0)`. */
|
|
75
|
+
export declare const translateToCanvas: Project["translateToCanvas"];
|
|
76
|
+
/** Convert canvas coordinates to world coordinates. Example: `translateToCenter(100, 100)`. */
|
|
77
|
+
export declare const translateToCenter: Project["translateToCenter"];
|
|
78
|
+
/** Whether a key is held, e.g. `pressing.includes('UP')`. */
|
|
79
|
+
export declare const pressing: {
|
|
80
|
+
/** Test a WoofJS key name. Example: `pressing.includes('UP')`. */
|
|
81
|
+
includes: (key: string) => boolean;
|
|
82
|
+
};
|
|
83
|
+
/** Set the background color of the beginner project. */
|
|
84
|
+
export declare const setBackdropColor: (color: string) => Project;
|
|
85
|
+
/** Set a backdrop image. Example: `setBackdropURL('sky.png')`. */
|
|
86
|
+
export declare const setBackdropURL: Project["setBackdropURL"];
|
|
87
|
+
/** Resize the backdrop. Example: `setBackdropSize(400, 300)`. */
|
|
88
|
+
export declare const setBackdropSize: Project["setBackdropSize"];
|
|
89
|
+
/** Set the CSS backdrop size style. Example: `setBackdropStyle('cover')`. */
|
|
90
|
+
export declare const setBackdropStyle: Project["setBackdropStyle"];
|
|
91
|
+
/** Set backdrop repetition. Example: `setBackdropRepeat('repeat')`. */
|
|
92
|
+
export declare const setBackdropRepeat: Project["setBackdropRepeat"];
|
|
93
|
+
/** Return the visible world bounds. Example: `bounds().left`. */
|
|
94
|
+
export declare const bounds: Project["bounds"];
|
|
95
|
+
/** Pick a whole-number x coordinate in the visible world. Example: `randomX()`. */
|
|
96
|
+
export declare const randomX: Project["randomX"];
|
|
97
|
+
/** Pick a whole-number y coordinate in the visible world. Example: `randomY()`. */
|
|
98
|
+
export declare const randomY: Project["randomY"];
|
|
99
|
+
/** Remove all pen trails. Example: `clearPen()`. */
|
|
100
|
+
export declare const clearPen: Project["clearPen"];
|
|
101
|
+
/** Read elapsed game time in seconds. Example: `timer()`. */
|
|
102
|
+
export declare const timer: Project["timer"];
|
|
103
|
+
/** Reset the game timer. Example: `resetTimer()`. */
|
|
104
|
+
export declare const resetTimer: Project["resetTimer"];
|
|
105
|
+
/** Pause game-time updates. Example: `freeze()`. */
|
|
106
|
+
export declare const freeze: Project["freeze"];
|
|
107
|
+
/** Resume game-time updates. Example: `defrost()`. */
|
|
108
|
+
export declare const defrost: Project["defrost"];
|
|
109
|
+
/** Register a scene setup function. Example: `scene('menu', showMenu)`. */
|
|
110
|
+
export declare const scene: Project["scene"];
|
|
111
|
+
/** Enter a registered scene. Example: `go('menu')`. */
|
|
112
|
+
export declare const go: Project["go"];
|
|
113
|
+
/** Find sprites carrying a tag. Example: `find('enemy')`. */
|
|
114
|
+
export declare const find: Project["find"];
|
|
115
|
+
/** Create a burst of temporary sprites. Example: `particles({ count: 5 })`. */
|
|
116
|
+
export declare const particles: Project["particles"];
|
|
117
|
+
/** Save a JSON value in project storage. Example: `save('score', 10)`. */
|
|
118
|
+
export declare const save: Project["save"];
|
|
119
|
+
/** Load a stored JSON value or use a fallback. Example: `load('score', 0)`. */
|
|
120
|
+
export declare const load: Project["load"];
|
|
121
|
+
/** Run a callback each frame with elapsed seconds. Example: `onUpdate(dt => {})`. */
|
|
122
|
+
export declare const onUpdate: Project["onUpdate"];
|
|
123
|
+
/** Subscribe to a key press. Example: `onKeyDown(key => {})`. */
|
|
124
|
+
export declare const onKeyDown: Project["onKeyDown"];
|
|
125
|
+
/** Subscribe to a key release. Example: `onKeyUp(key => {})`. */
|
|
126
|
+
export declare const onKeyUp: Project["onKeyUp"];
|
|
127
|
+
/** Subscribe to pointer presses. Example: `onMouseDown((x, y) => {})`. */
|
|
128
|
+
export declare const onMouseDown: Project["onMouseDown"];
|
|
129
|
+
/** Subscribe to pointer releases. Example: `onMouseUp((x, y) => {})`. */
|
|
130
|
+
export declare const onMouseUp: Project["onMouseUp"];
|
|
131
|
+
/** Subscribe to pointer movement. Example: `onMouseMove((x, y) => {})`. */
|
|
132
|
+
export declare const onMouseMove: Project["onMouseMove"];
|
|
133
|
+
/** Subscribe to touch contacts and receive world coordinates and finger id. */
|
|
134
|
+
export declare const onTouchStart: Project["onTouchStart"];
|
|
135
|
+
/** Subscribe to touch movement. */
|
|
136
|
+
export declare const onTouchMove: Project["onTouchMove"];
|
|
137
|
+
/** Subscribe to completed touch contacts. */
|
|
138
|
+
export declare const onTouchEnd: Project["onTouchEnd"];
|
|
139
|
+
/** Subscribe to cancelled touch contacts. */
|
|
140
|
+
export declare const onTouchCancel: Project["onTouchCancel"];
|
|
141
|
+
/** Pointer coordinates and button state for the beginner project. */
|
|
142
|
+
export declare const mouse: {
|
|
143
|
+
/** Pointer x coordinate in world units. Example: `mouse.x`. */
|
|
144
|
+
readonly x: number;
|
|
145
|
+
/** Pointer y coordinate in world units. Example: `mouse.y`. */
|
|
146
|
+
readonly y: number;
|
|
147
|
+
/** Whether a pointer is pressed. Example: `mouse.down`. */
|
|
148
|
+
readonly down: boolean;
|
|
149
|
+
};
|
|
150
|
+
/** Dimensions, bounds and sprites of the beginner project. */
|
|
151
|
+
export declare const world: {
|
|
152
|
+
/** Width of the visible world. Example: `world.width`. */
|
|
153
|
+
readonly width: number;
|
|
154
|
+
/** Height of the visible world. Example: `world.height`. */
|
|
155
|
+
readonly height: number;
|
|
156
|
+
/** Left edge of the visible world. Example: `world.minX`. */
|
|
157
|
+
readonly minX: number;
|
|
158
|
+
/** Right edge of the visible world. Example: `world.maxX`. */
|
|
159
|
+
readonly maxX: number;
|
|
160
|
+
/** Bottom edge of the visible world. Example: `world.minY`. */
|
|
161
|
+
readonly minY: number;
|
|
162
|
+
/** Top edge of the visible world. Example: `world.maxY`. */
|
|
163
|
+
readonly maxY: number;
|
|
164
|
+
/** Sprites currently in the project. Example: `world.sprites`. */
|
|
165
|
+
readonly sprites: SpriteInstance[];
|
|
166
|
+
};
|
|
167
|
+
export * from "./helpers.js";
|
package/dist/types/sound.d.ts
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
export interface SoundOptions {
|
|
2
|
-
/** Initial linear gain, in the Web Audio gain scale. */
|
|
2
|
+
/** Initial linear gain, in the Web Audio gain scale. Example: `createSound(buffer, audioContext, { volume: 0.5 })`. */
|
|
3
3
|
volume?: number;
|
|
4
|
-
/** Upper bound for gain values produced by amplify(); defaults to 4. */
|
|
4
|
+
/** Upper bound for gain values produced by amplify(); defaults to 4. Example: `createSound(buffer, audioContext, { maxGain: 3 })`. */
|
|
5
5
|
maxGain?: number;
|
|
6
6
|
}
|
|
7
7
|
export interface PlaybackOptions {
|
|
8
|
+
/** Whether the playback repeats. Example: `sound.startPlaying({ loop: true })`. */
|
|
8
9
|
loop?: boolean;
|
|
10
|
+
/** Playback rate multiplier. Example: `sound.startPlaying({ playbackRate: 2 })`. */
|
|
9
11
|
playbackRate?: number;
|
|
10
12
|
}
|
|
11
13
|
export interface Playback {
|
|
14
|
+
/** Web Audio source for this playback. */
|
|
12
15
|
readonly source: AudioBufferSourceNode;
|
|
16
|
+
/** Whether this playback has been stopped. */
|
|
13
17
|
readonly stopped: boolean;
|
|
14
|
-
|
|
18
|
+
/** Multiply playback volume up to its configured maximum. */
|
|
19
|
+
amplify(multiplier: number | "max"): this;
|
|
20
|
+
/** Stop this playback. */
|
|
15
21
|
stop(): this;
|
|
16
22
|
}
|
|
17
23
|
export interface Sound {
|
|
24
|
+
/** Start playback and return its controls. */
|
|
18
25
|
startPlaying(options?: PlaybackOptions): Playback;
|
|
19
26
|
}
|
|
20
27
|
/** Create a reusable sound backed by a Web Audio AudioBuffer. */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Project } from "../woof.js";
|
|
2
|
+
import type { Sprite, SpriteOptions } from "./sprite.js";
|
|
3
|
+
/** Build a project-bound constructor from an upstream-style render definition. */
|
|
4
|
+
export declare function createCustomSprite<T extends {
|
|
5
|
+
render: (ctx: CanvasRenderingContext2D) => void;
|
|
6
|
+
}>(project: Project, definition: T & ThisType<Sprite & T>): {
|
|
7
|
+
(options?: SpriteOptions): Sprite & T;
|
|
8
|
+
new (options?: SpriteOptions): Sprite & T;
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Easing curves that tween accepts by name. Example: `sprite.tween({ x: 10 }, 1, 'easeOut')`. */
|
|
2
|
+
export declare const easings: {
|
|
3
|
+
linear: (t: number) => number;
|
|
4
|
+
easeIn: (t: number) => number;
|
|
5
|
+
easeOut: (t: number) => number;
|
|
6
|
+
easeInOut: (t: number) => number;
|
|
7
|
+
};
|
|
8
|
+
/** The name of a built-in easing curve. Example: `const name: EasingName = 'easeIn'`. */
|
|
9
|
+
export type EasingName = keyof typeof easings;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Collider } from "../collision.js";
|
|
2
|
+
import type { Sprite } from "./sprite.js";
|
|
3
|
+
/** Construct the collision geometry for a sprite in world coordinates. */
|
|
4
|
+
export declare function spriteCollider(sprite: Sprite): Collider;
|
|
5
|
+
/** Compute the axis-aligned world bounds of a sprite. */
|
|
6
|
+
export declare function spriteBounds(sprite: Sprite): {
|
|
7
|
+
left: number;
|
|
8
|
+
right: number;
|
|
9
|
+
top: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
};
|
|
12
|
+
/** Test visible sprites, descending into bundles when necessary. */
|
|
13
|
+
export declare function spritesTouching(sprite: Sprite, other: Sprite, precise: boolean): boolean;
|
|
14
|
+
/** Test a sprite against a world-space rectangle. */
|
|
15
|
+
export declare function spriteOverlaps(sprite: Sprite, bounds: {
|
|
16
|
+
left: number;
|
|
17
|
+
right: number;
|
|
18
|
+
top: number;
|
|
19
|
+
bottom: number;
|
|
20
|
+
}): boolean;
|
|
21
|
+
/** Test a point in world coordinates against a visible sprite. */
|
|
22
|
+
export declare function spriteOver(sprite: Sprite, x: number, y: number): boolean;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Sprite } from "./sprite.js";
|
|
2
|
+
import type { Project } from "../woof.js";
|
|
3
|
+
export type SpriteType = "circle" | "rectangle" | "oval" | "polygon" | "line" | "text" | "image" | "bundle" | "sprite";
|
|
4
|
+
export interface StaticSpriteOptions {
|
|
5
|
+
/** Project that owns the sprite. Defaults to the beginner project. Example: `new Sprite({ project: game })`. */
|
|
6
|
+
project?: Project;
|
|
7
|
+
/** Horizontal world coordinate, increasing to the right. Example: `new Sprite({ x: 10 })`. */
|
|
8
|
+
x?: number;
|
|
9
|
+
/** Vertical world coordinate, increasing upwards. Example: `new Sprite({ y: 20 })`. */
|
|
10
|
+
y?: number;
|
|
11
|
+
/** Direction in degrees, counter-clockwise from the right. Example: `new Sprite({ angle: 90 })`. */
|
|
12
|
+
angle?: number;
|
|
13
|
+
/** Controls whether the sprite rotates or flips with its angle. Example: `new Sprite({ rotationStyle: 'NO ROTATE' })`. */
|
|
14
|
+
rotationStyle?: string;
|
|
15
|
+
/** Whether this sprite is drawn. Example: `new Sprite({ showing: false })`. */
|
|
16
|
+
showing?: boolean;
|
|
17
|
+
/** Start drawing a trail as this sprite moves. Example: `new Sprite({ penDown: true })`. */
|
|
18
|
+
penDown?: boolean;
|
|
19
|
+
/** Color used when drawing a trail. Example: `new Sprite({ penColor: 'blue' })`. */
|
|
20
|
+
penColor?: string;
|
|
21
|
+
/** Width of the trail in world units. Example: `new Sprite({ penWidth: 2 })`. */
|
|
22
|
+
penWidth?: number;
|
|
23
|
+
/** Whether to draw the collision outline. Example: `new Sprite({ showCollider: true })`. */
|
|
24
|
+
showCollider?: boolean;
|
|
25
|
+
/** Rendering brightness as a percentage. Example: `new Sprite({ brightness: 80 })`. */
|
|
26
|
+
brightness?: number;
|
|
27
|
+
/** Sprite width in world units. Example: `new Sprite({ width: 20 })`. */
|
|
28
|
+
width?: number;
|
|
29
|
+
/** Sprite height in world units. Example: `new Sprite({ height: 30 })`. */
|
|
30
|
+
height?: number;
|
|
31
|
+
/** Circle radius in world units. Example: `new Sprite({ radius: 10 })`. */
|
|
32
|
+
radius?: number;
|
|
33
|
+
/** Number of sides in a regular polygon. Example: `new Sprite({ sides: 5 })`. */
|
|
34
|
+
sides?: number;
|
|
35
|
+
/** Distance from the centre to a regular polygon's vertices. Example: `new Sprite({ length: 30 })`. */
|
|
36
|
+
length?: number;
|
|
37
|
+
/** World x coordinate of the end of a line. Example: `new Sprite({ x1: 10 })`. */
|
|
38
|
+
x1?: number;
|
|
39
|
+
/** World y coordinate of the end of a line. Example: `new Sprite({ y1: 20 })`. */
|
|
40
|
+
y1?: number;
|
|
41
|
+
/** Fill or stroke color used to render the sprite. Example: `new Sprite({ color: 'red' })`. */
|
|
42
|
+
color?: string;
|
|
43
|
+
/** Text size in pixels. Example: `new Sprite({ size: 24 })`. */
|
|
44
|
+
size?: number;
|
|
45
|
+
/** Text to display, or a function evaluated when rendered. Example: `new Sprite({ text: 'Score' })`. */
|
|
46
|
+
text?: string | (() => unknown);
|
|
47
|
+
/** Horizontal alignment of text. Example: `new Sprite({ textAlign: 'left' })`. */
|
|
48
|
+
textAlign?: CanvasTextAlign;
|
|
49
|
+
/** Font family used for text. Example: `new Sprite({ fontFamily: 'sans-serif' })`. */
|
|
50
|
+
fontFamily?: string;
|
|
51
|
+
/** Image URL used by this sprite. Example: `new Sprite({ url: 'player.png' })`. */
|
|
52
|
+
url?: string;
|
|
53
|
+
/** Rendering opacity from zero to one. Example: `new Sprite({ opacity: 0.5 })`. */
|
|
54
|
+
opacity?: number;
|
|
55
|
+
/** Uniform rendering and collision scale. Example: `new Sprite({ scale: 2 })`. */
|
|
56
|
+
scale?: number;
|
|
57
|
+
/** Horizontal velocity in world units per second. Example: `new Sprite({ vx: 10 })`. */
|
|
58
|
+
vx?: number;
|
|
59
|
+
/** Vertical velocity in world units per second. Example: `new Sprite({ vy: 20 })`. */
|
|
60
|
+
vy?: number;
|
|
61
|
+
/** Vertical acceleration in world units per second squared. Example: `new Sprite({ gravity: -9 })`. */
|
|
62
|
+
gravity?: number;
|
|
63
|
+
/** Whether the sprite bounces off world edges. Example: `new Sprite({ bounce: true })`. */
|
|
64
|
+
bounce?: boolean;
|
|
65
|
+
/** Whether the sprite wraps around world edges. Example: `new Sprite({ wrap: true })`. */
|
|
66
|
+
wrap?: boolean;
|
|
67
|
+
/** Labels used to find sprites and subscribe to touches. Example: `new Sprite({ tags: ['enemy'] })`. */
|
|
68
|
+
tags?: string[];
|
|
69
|
+
/** Application-defined data associated with the sprite. Example: `new Sprite({ data: { score: 0 } })`. */
|
|
70
|
+
data?: Record<string, unknown>;
|
|
71
|
+
/** Drawing order; higher layers are drawn later. Example: `new Sprite({ layer: 2 })`. */
|
|
72
|
+
layer?: number;
|
|
73
|
+
/** Custom drawing callback for a sprite. Example: `new Sprite({ draw: ctx => ctx.fillRect(0, 0, 5, 5) })`. */
|
|
74
|
+
draw?: (ctx: CanvasRenderingContext2D) => void;
|
|
75
|
+
/** Callback run with the sprite and elapsed seconds each frame. Example: `new Sprite({ update: (sprite, dt) => sprite.move(dt * 10) })`. */
|
|
76
|
+
update?: (sprite: Sprite, dt: number) => void;
|
|
77
|
+
/** Image URLs available to the sprite. Example: `new Sprite({ costumes: ['idle.png', 'jump.png'] })`. */
|
|
78
|
+
costumes?: string[];
|
|
79
|
+
/** Whether to flip the image horizontally. Example: `new Sprite({ flipX: true })`. */
|
|
80
|
+
flipX?: boolean;
|
|
81
|
+
/** Whether to flip the image vertically. Example: `new Sprite({ flipY: true })`. */
|
|
82
|
+
flipY?: boolean;
|
|
83
|
+
/** Dimensions and count of image sheet frames. Example: `new Sprite({ frames: { width: 16, height: 16, count: 4 } })`. */
|
|
84
|
+
frames?: {
|
|
85
|
+
/** Width of each frame in pixels. Example: `frames: { width: 16, height: 16, count: 4 }`. */
|
|
86
|
+
width: number;
|
|
87
|
+
/** Height of each frame in pixels. Example: `frames: { width: 16, height: 16, count: 4 }`. */
|
|
88
|
+
height: number;
|
|
89
|
+
/** Number of frames in the sheet. Example: `frames: { width: 16, height: 16, count: 4 }`. */
|
|
90
|
+
count: number;
|
|
91
|
+
};
|
|
92
|
+
/** Sprites contained in this bundle. Example: `new Sprite({ components: [player] })`. */
|
|
93
|
+
components?: Sprite[];
|
|
94
|
+
}
|
|
95
|
+
/** Sprite settings can be live functions; draw and update remain callbacks. */
|
|
96
|
+
export type SpriteOptions = {
|
|
97
|
+
[K in keyof StaticSpriteOptions]: K extends "draw" | "update" | "text" | "project" ? StaticSpriteOptions[K] : StaticSpriteOptions[K] | (() => Exclude<StaticSpriteOptions[K], undefined>);
|
|
98
|
+
};
|