like2d 2.11.0 → 2.12.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/README.md +36 -6
- package/assets/logo-banner-optimized.svg +15 -27
- package/assets/logo-banner.svg +76 -132
- package/assets/logo-icon.svg +33 -23
- package/assets/logo.svg +78 -123
- package/dist/audio/index.d.ts +1 -1
- package/dist/engine.d.ts +5 -8
- package/dist/engine.js +37 -22
- package/dist/events.d.ts +19 -7
- package/dist/graphics/canvas.d.ts +23 -7
- package/dist/graphics/canvas.js +69 -68
- package/dist/graphics/graphics.d.ts +83 -55
- package/dist/graphics/graphics.js +128 -129
- package/dist/graphics/image.d.ts +22 -0
- package/dist/graphics/image.js +62 -0
- package/dist/graphics/index.d.ts +6 -4
- package/dist/graphics/index.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +9 -2
- package/dist/input/controllerdb.json +1 -1
- package/dist/input/gamepad-mapping.d.ts +4 -4
- package/dist/input/gamepad-mapping.js +6 -5
- package/dist/input/gamepad.d.ts +11 -1
- package/dist/input/gamepad.js +11 -1
- package/dist/input/index.d.ts +13 -5
- package/dist/input/index.js +5 -1
- package/dist/input/input.d.ts +58 -7
- package/dist/input/input.js +63 -9
- package/dist/input/keyboard.d.ts +26 -3
- package/dist/input/keyboard.js +24 -0
- package/dist/input/mouse.d.ts +34 -6
- package/dist/input/mouse.js +31 -3
- package/dist/like.d.ts +41 -12
- package/dist/like.js +0 -4
- package/dist/math/index.d.ts +8 -9
- package/dist/math/index.js +8 -9
- package/dist/math/vector2.d.ts +2 -1
- package/dist/prefab-scenes/index.d.ts +5 -3
- package/dist/prefab-scenes/index.js +4 -2
- package/dist/prefab-scenes/mapGamepad.d.ts +14 -2
- package/dist/prefab-scenes/mapGamepad.js +29 -22
- package/dist/prefab-scenes/startScreen.d.ts +2 -3
- package/dist/prefab-scenes/startScreen.js +41 -12
- package/dist/scene.d.ts +48 -13
- package/dist/scene.js +0 -5
- package/package.json +2 -2
- package/dist/__benchmarks__/vector2.bench.d.ts +0 -2
- package/dist/__benchmarks__/vector2.bench.d.ts.map +0 -1
- package/dist/__benchmarks__/vector2.bench.js +0 -74
- package/dist/audio/audio.d.ts.map +0 -1
- package/dist/audio/index.d.ts.map +0 -1
- package/dist/engine.d.ts.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/graphics/canvas.d.ts.map +0 -1
- package/dist/graphics/graphics.d.ts.map +0 -1
- package/dist/graphics/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/input/gamepad-mapping.d.ts.map +0 -1
- package/dist/input/gamepad.d.ts.map +0 -1
- package/dist/input/index.d.ts.map +0 -1
- package/dist/input/input.d.ts.map +0 -1
- package/dist/input/keyboard.d.ts.map +0 -1
- package/dist/input/mouse.d.ts.map +0 -1
- package/dist/like.d.ts.map +0 -1
- package/dist/math/index.d.ts.map +0 -1
- package/dist/math/rect.d.ts.map +0 -1
- package/dist/math/vector2.d.ts.map +0 -1
- package/dist/prefab-scenes/index.d.ts.map +0 -1
- package/dist/prefab-scenes/mapGamepad.d.ts.map +0 -1
- package/dist/prefab-scenes/startScreen.d.ts.map +0 -1
- package/dist/scene.d.ts.map +0 -1
- package/dist/timer/index.d.ts.map +0 -1
- package/dist/timer/timer.d.ts.map +0 -1
package/dist/graphics/canvas.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Rect } from "../math/rect";
|
|
2
2
|
import { Vec2 } from "../math/vector2";
|
|
3
|
+
/**
|
|
4
|
+
* A manager for the HTML canvas element, similar to `love.window`.
|
|
5
|
+
*
|
|
6
|
+
* Controls game size / scaling -- both native and pixelart mode via {@link Canvas.setMode}, as well as fullscreen functions.
|
|
7
|
+
*
|
|
8
|
+
* The canvas keeps two canvases: render and display. Each frame, it copies render to display before the canvas is presented.
|
|
9
|
+
* This allows for pixel-accurate scaling.
|
|
10
|
+
*/
|
|
3
11
|
export class Canvas {
|
|
4
12
|
constructor(
|
|
5
13
|
/** The ultimately visible canvas in the browser */
|
|
@@ -22,10 +30,7 @@ export class Canvas {
|
|
|
22
30
|
writable: true,
|
|
23
31
|
value: abort
|
|
24
32
|
});
|
|
25
|
-
/** The canvas that we're drawing to with `like.gfx` functions.
|
|
26
|
-
* If it's the same as displayCanvas, we're in native mode.
|
|
27
|
-
* Otherwise, we're in pixelart mode, consisting of nearest -> linear scaling.
|
|
28
|
-
*/
|
|
33
|
+
/** The canvas that we're drawing to with `like.gfx` functions. */
|
|
29
34
|
Object.defineProperty(this, "renderCanvas", {
|
|
30
35
|
enumerable: true,
|
|
31
36
|
configurable: true,
|
|
@@ -38,42 +43,39 @@ export class Canvas {
|
|
|
38
43
|
writable: true,
|
|
39
44
|
value: 0
|
|
40
45
|
});
|
|
46
|
+
Object.defineProperty(this, "isNativeMode", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: true
|
|
51
|
+
});
|
|
41
52
|
displayCanvas.tabIndex = 0;
|
|
42
53
|
displayCanvas.style.width = '100%';
|
|
43
54
|
displayCanvas.style.height = '100%';
|
|
44
|
-
|
|
55
|
+
displayCanvas.style.objectFit = 'contain';
|
|
56
|
+
// Always create a separate render canvas
|
|
57
|
+
this.renderCanvas = document.createElement('canvas');
|
|
45
58
|
this.setMode('native');
|
|
46
59
|
/** Only the canvas can really transform the mouse to the game size.
|
|
47
60
|
* This hack sends an event for the mouse module to listen to.
|
|
48
61
|
*/
|
|
49
62
|
this.displayCanvas.addEventListener('mousemove', (ev) => {
|
|
50
|
-
let pos;
|
|
51
|
-
let delta;
|
|
52
63
|
const rawPos = [ev.offsetX, ev.offsetY];
|
|
53
64
|
const rawDelta = [ev.movementX, ev.movementY];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const scale = calcAspectFriendlyScale(this.getSize(), csize);
|
|
69
|
-
/* Upper-left corner */
|
|
70
|
-
const offset = Vec2.div(Vec2.sub(csize, Vec2.mul(this.getSize(), scale)), 2);
|
|
71
|
-
pos = Vec2.div(Vec2.sub(rawPos, offset), scale);
|
|
72
|
-
delta = Vec2.div(rawDelta, scale);
|
|
73
|
-
/* Only handle mousemove events that are in bounds. */
|
|
74
|
-
if (!Rect.containsPoint(this.getRect(), pos)) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
65
|
+
/* Recreation of object-fit */
|
|
66
|
+
const csize = [
|
|
67
|
+
this.displayCanvas.clientWidth,
|
|
68
|
+
this.displayCanvas.clientHeight
|
|
69
|
+
];
|
|
70
|
+
/* Scale of both dimensions */
|
|
71
|
+
const scale = calcAspectFriendlyScale(this.getSize(), csize);
|
|
72
|
+
/* Upper-left corner */
|
|
73
|
+
const offset = Vec2.div(Vec2.sub(csize, Vec2.mul(this.getSize(), scale)), 2);
|
|
74
|
+
const pos = Vec2.div(Vec2.sub(rawPos, offset), scale);
|
|
75
|
+
const delta = Vec2.div(rawDelta, scale);
|
|
76
|
+
/* Only handle mousemove events that are in bounds. */
|
|
77
|
+
if (!Rect.containsPoint(this.getRect(), pos)) {
|
|
78
|
+
return;
|
|
77
79
|
}
|
|
78
80
|
this.displayCanvas.dispatchEvent(new CustomEvent('like:mousemoved', {
|
|
79
81
|
detail: {
|
|
@@ -85,6 +87,14 @@ export class Canvas {
|
|
|
85
87
|
this.displayCanvas.addEventListener("like:preDraw", this.preDraw.bind(this), { signal: this.abort });
|
|
86
88
|
this.displayCanvas.addEventListener("like:postDraw", this.postDraw.bind(this), { signal: this.abort });
|
|
87
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the canvas that graphics functions render to.
|
|
92
|
+
* This is separate from the display canvas; it is
|
|
93
|
+
* not visibly exposed but rather copied each frame.
|
|
94
|
+
*/
|
|
95
|
+
getContext() {
|
|
96
|
+
return this.renderCanvas.getContext('2d');
|
|
97
|
+
}
|
|
88
98
|
/** Get a unified canvas info object. */
|
|
89
99
|
getMode() {
|
|
90
100
|
return {
|
|
@@ -110,27 +120,13 @@ export class Canvas {
|
|
|
110
120
|
* @param flags optional options.
|
|
111
121
|
*/
|
|
112
122
|
setMode(size, flags = {}) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (size == 'native') {
|
|
116
|
-
this.displayCanvas.style.objectFit = 'fill';
|
|
117
|
-
this.renderCanvas = this.displayCanvas;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.displayCanvas.style.objectFit = 'contain';
|
|
121
|
-
this.renderCanvas = document.createElement('canvas');
|
|
123
|
+
this.isNativeMode = size === 'native';
|
|
124
|
+
if (size !== 'native') {
|
|
122
125
|
const changed = Canvas.setCanvasElemSize(this.renderCanvas, size);
|
|
123
126
|
if (changed) {
|
|
124
127
|
this.dispatchResize(size);
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
|
-
if (prevRenderCanvas != this.renderCanvas) {
|
|
128
|
-
this.displayCanvas.dispatchEvent(new CustomEvent("like:updateRenderTarget", {
|
|
129
|
-
detail: {
|
|
130
|
-
target: this.renderCanvas,
|
|
131
|
-
},
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
130
|
if ('fullscreen' in flags) {
|
|
135
131
|
this.setFullscreen(flags.fullscreen);
|
|
136
132
|
}
|
|
@@ -159,6 +155,10 @@ export class Canvas {
|
|
|
159
155
|
getFullscreen() {
|
|
160
156
|
return this.displayCanvas === document.fullscreenElement;
|
|
161
157
|
}
|
|
158
|
+
/** Does the canvas have focus? */
|
|
159
|
+
hasFocus() {
|
|
160
|
+
return document.activeElement === this.displayCanvas;
|
|
161
|
+
}
|
|
162
162
|
/** Set fullscreen. */
|
|
163
163
|
setFullscreen(fullscreen) {
|
|
164
164
|
if (fullscreen) {
|
|
@@ -172,49 +172,50 @@ export class Canvas {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
176
|
-
* rendering a frame.
|
|
175
|
+
* Trigered by `like:preDraw`
|
|
177
176
|
*/
|
|
178
177
|
preDraw() {
|
|
179
|
-
if (this.
|
|
178
|
+
if (this.isNativeMode) {
|
|
179
|
+
// In native mode, renderCanvas tracks display size
|
|
180
180
|
const realSize = this.getDisplayPixelSize();
|
|
181
|
-
if ((realSize[0] != this.
|
|
182
|
-
realSize[1] != this.
|
|
181
|
+
if ((realSize[0] != this.renderCanvas.width ||
|
|
182
|
+
realSize[1] != this.renderCanvas.height) &&
|
|
183
183
|
!this.resizeTimeoutId) {
|
|
184
184
|
/** In native scaling mode, zooming and resizing the window cause us
|
|
185
185
|
* to set canvas width and height every frame, which could cause
|
|
186
186
|
* tons of canvas bitmap reallocations. So wait 1/4 second..
|
|
187
187
|
*/
|
|
188
|
-
Canvas.setCanvasElemSize(this.
|
|
188
|
+
Canvas.setCanvasElemSize(this.renderCanvas, realSize);
|
|
189
189
|
this.dispatchResize(realSize);
|
|
190
190
|
this.resizeTimeoutId = setTimeout(() => { this.resizeTimeoutId = 0; }, 250);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
this.renderCanvas.getContext('2d')
|
|
193
|
+
const ctx = this.renderCanvas.getContext('2d');
|
|
194
|
+
ctx.resetTransform();
|
|
195
|
+
// Enable smoothing in native mode, disable in pixelart mode
|
|
196
|
+
ctx.imageSmoothingEnabled = this.isNativeMode;
|
|
194
197
|
}
|
|
195
|
-
/**
|
|
198
|
+
/** Triggered by `like:postDraw` */
|
|
196
199
|
postDraw() {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
// Always blit from render canvas to display canvas
|
|
201
|
+
if (this.isNativeMode) {
|
|
202
|
+
// In native mode, display canvas matches render canvas size
|
|
203
|
+
Canvas.setCanvasElemSize(this.displayCanvas, this.getSize());
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
// In pixelart mode, set output canvas size to an ideal integer scale
|
|
202
207
|
Canvas.setCanvasElemSize(this.displayCanvas, Vec2.mul(this.getSize(), Math.round(calcAspectFriendlyScale(this.getSize(), this.getDisplayPixelSize()))));
|
|
203
|
-
// Copy the internal canvas to the visible one.
|
|
204
|
-
const ctx = this.displayCanvas.getContext('2d');
|
|
205
|
-
ctx.imageSmoothingEnabled = false;
|
|
206
|
-
ctx.drawImage(this.renderCanvas, 0, 0, this.renderCanvas.width, this.renderCanvas.height, 0, 0, this.displayCanvas.width, this.displayCanvas.height);
|
|
207
208
|
}
|
|
209
|
+
// Copy the render canvas to the visible one
|
|
210
|
+
const displayCtx = this.displayCanvas.getContext('2d');
|
|
211
|
+
displayCtx.imageSmoothingEnabled = false;
|
|
212
|
+
displayCtx.drawImage(this.renderCanvas, 0, 0, this.renderCanvas.width, this.renderCanvas.height, 0, 0, this.displayCanvas.width, this.displayCanvas.height);
|
|
208
213
|
}
|
|
209
214
|
/** @returns if size was changed. */
|
|
210
215
|
static setCanvasElemSize(canvas, newSize) {
|
|
211
|
-
const ctx = canvas.getContext('2d');
|
|
212
|
-
if (!ctx)
|
|
213
|
-
return false;
|
|
214
216
|
if (canvas.width === newSize[0] && canvas.height === newSize[1])
|
|
215
217
|
return false;
|
|
216
|
-
canvas.width = newSize
|
|
217
|
-
canvas.height = newSize[1];
|
|
218
|
+
[canvas.width, canvas.height] = newSize;
|
|
218
219
|
return true;
|
|
219
220
|
}
|
|
220
221
|
static getCanvasElemSize(canvas) {
|
|
@@ -26,8 +26,9 @@
|
|
|
26
26
|
* - Y increases down
|
|
27
27
|
* - Angles in radians, 0 is right, positive is clockwise
|
|
28
28
|
*/
|
|
29
|
-
import {
|
|
29
|
+
import type { Vector2 } from "../math/vector2";
|
|
30
30
|
import type { Rectangle } from "../math/rect";
|
|
31
|
+
import { ImageHandle } from "./image";
|
|
31
32
|
export type DrawMode = "fill" | "line";
|
|
32
33
|
/**
|
|
33
34
|
* - RGBA array with values 0-1: `[r, g, b, a]`
|
|
@@ -35,64 +36,72 @@ export type DrawMode = "fill" | "line";
|
|
|
35
36
|
* - CSS color strings also accepted: `"red"`, `"#ff0000"`, `"rgb(255,0,0)"`
|
|
36
37
|
*/
|
|
37
38
|
export type Color = [number, number, number, number?] | string;
|
|
39
|
+
export type TransformProps = {
|
|
40
|
+
angle?: number;
|
|
41
|
+
scale?: number | Vector2;
|
|
42
|
+
origin?: Vector2;
|
|
43
|
+
};
|
|
38
44
|
export type ShapeProps = {
|
|
39
45
|
lineWidth?: number;
|
|
40
46
|
lineCap?: CanvasLineCap;
|
|
41
47
|
lineJoin?: CanvasLineJoin;
|
|
42
48
|
miterLimit?: number;
|
|
43
|
-
};
|
|
49
|
+
} & TransformProps;
|
|
44
50
|
export type DrawProps = ShapeProps & {
|
|
45
51
|
quad?: Rectangle;
|
|
46
|
-
r?: number;
|
|
47
|
-
scale?: number | Vector2;
|
|
48
|
-
origin?: number | Vector2;
|
|
49
52
|
};
|
|
50
53
|
export type PrintProps = {
|
|
51
54
|
font?: string;
|
|
52
55
|
width?: number;
|
|
53
56
|
align?: CanvasTextAlign;
|
|
54
|
-
};
|
|
55
|
-
export declare class ImageHandle {
|
|
56
|
-
readonly path: string;
|
|
57
|
-
private element;
|
|
58
|
-
private loadPromise;
|
|
59
|
-
private isLoaded;
|
|
60
|
-
constructor(path: string);
|
|
61
|
-
isReady(): boolean;
|
|
62
|
-
ready(): Promise<void>;
|
|
63
|
-
get size(): Vector2;
|
|
64
|
-
getElement(): HTMLImageElement | null;
|
|
65
|
-
}
|
|
57
|
+
} & TransformProps;
|
|
66
58
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
59
|
+
* LIKE's way of drawing to the screen.
|
|
60
|
+
*
|
|
61
|
+
* More specifically: a system for wrapping canvas draw calls conveniently.
|
|
69
62
|
*
|
|
70
|
-
*
|
|
63
|
+
* - Reduces state in calls -- no `setColor`, etc. Everything is passed in.
|
|
64
|
+
* - Abstracts away common drawing operations.
|
|
71
65
|
*
|
|
66
|
+
* ### Examples
|
|
67
|
+
* Draw a spinning symbol in the center of the screen using transforms.
|
|
72
68
|
* ```ts
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
69
|
+
* function drawSpinningYinYang(like: Like) {
|
|
70
|
+
* const color1 = "black";
|
|
71
|
+
* const color2 = "white";
|
|
72
|
+
* const size = 50;
|
|
73
|
+
* const pos = Vec2.div(like.canvas.getSize(), 2); // calc center of screen
|
|
74
|
+
* const speed = 0.5; // rotations per second
|
|
75
|
+
*
|
|
76
|
+
* like.gfx.withTransform(() => {
|
|
77
|
+
* like.gfx.translate(pos);
|
|
78
|
+
* like.gfx.rotate(like.timer.getTime() * Math.PI * 2.0 * speed);
|
|
79
|
+
* like.gfx.scale(size);
|
|
80
|
+
* like.gfx.circle("fill", color1, [0, 0], 2);
|
|
81
|
+
* // use the arc parameter to fill in a semicircle. Note that it's clockwise from {x:1, y:0}.
|
|
82
|
+
* like.gfx.circle("fill", color2, [0, 0], 2, { arc: [Math.PI/2, Math.PI*3/2] });
|
|
83
|
+
* like.gfx.circle("fill", color2, [0, -1], 1);
|
|
84
|
+
* like.gfx.circle("fill", color1, [0, 1], 1);
|
|
85
|
+
* like.gfx.circle("fill", color2, [0, 1], 1/3);
|
|
86
|
+
* like.gfx.circle("fill", color1, [0, -1], 1/3);
|
|
87
|
+
* })
|
|
88
|
+
* }
|
|
76
89
|
*
|
|
90
|
+
* like.draw = (like: Like) => {
|
|
91
|
+
* drawSpinningYinYang(like);
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
77
94
|
*/
|
|
78
95
|
export declare class Graphics {
|
|
79
96
|
private ctx;
|
|
80
97
|
constructor(ctx: CanvasRenderingContext2D);
|
|
81
|
-
/**
|
|
82
|
-
* Set the 2d drawing context for graphics.
|
|
83
|
-
*
|
|
84
|
-
* Be aware that that `like` can set this value at any time.
|
|
85
|
-
*/
|
|
86
|
-
setContext(ctx: CanvasRenderingContext2D): void;
|
|
87
98
|
/**
|
|
88
99
|
* Clears the canvas with a solid color.
|
|
89
|
-
* @param this.ctx Canvas context.
|
|
90
100
|
* @param color Fill color.
|
|
91
101
|
*/
|
|
92
102
|
clear(color?: Color): void;
|
|
93
103
|
/**
|
|
94
104
|
* Draws a rectangle.
|
|
95
|
-
* @param this.ctx Canvas context.
|
|
96
105
|
* @param mode Fill or line.
|
|
97
106
|
* @param color Fill or stroke color.
|
|
98
107
|
* @param rect Rectangle [x, y, w, h].
|
|
@@ -101,20 +110,20 @@ export declare class Graphics {
|
|
|
101
110
|
rectangle(mode: DrawMode, color: Color, rect: Rectangle, props?: ShapeProps): void;
|
|
102
111
|
/**
|
|
103
112
|
* Draws a circle or ellipse.
|
|
104
|
-
|
|
113
|
+
|
|
105
114
|
* @param mode Fill or line.
|
|
106
115
|
* @param color Fill or stroke color.
|
|
107
116
|
* @param position Center position.
|
|
108
117
|
* @param radii Radius (number) or [rx, ry] for ellipse.
|
|
109
118
|
* @param props Optional arc, center, and stroke properties. Center is true by default.
|
|
110
119
|
*/
|
|
111
|
-
circle(mode: DrawMode, color: Color, position: Vector2,
|
|
120
|
+
circle(mode: DrawMode, color: Color, position: Vector2, radius: number, props?: ShapeProps & {
|
|
112
121
|
arc?: [number, number];
|
|
113
122
|
center?: boolean;
|
|
114
123
|
}): void;
|
|
115
124
|
/**
|
|
116
125
|
* Draws connected line segments.
|
|
117
|
-
|
|
126
|
+
|
|
118
127
|
* @param color Stroke color.
|
|
119
128
|
* @param points Array of [x, y] positions.
|
|
120
129
|
* @param props Optional stroke properties.
|
|
@@ -130,7 +139,7 @@ export declare class Graphics {
|
|
|
130
139
|
* to the left and right of its position. If you align right, your position
|
|
131
140
|
* becomes the upper-right corner of the text.
|
|
132
141
|
*
|
|
133
|
-
|
|
142
|
+
|
|
134
143
|
* @param color Fill color.
|
|
135
144
|
* @param text Text string.
|
|
136
145
|
* @param position Top-left position.
|
|
@@ -142,8 +151,7 @@ export declare class Graphics {
|
|
|
142
151
|
*
|
|
143
152
|
* @remarks named "draw" because it draws anything _drawable_
|
|
144
153
|
* in the long run.
|
|
145
|
-
|
|
146
|
-
* @param this.ctx Canvas context.
|
|
154
|
+
|
|
147
155
|
* @param handle Image handle from newImage.
|
|
148
156
|
* @param position Draw position.
|
|
149
157
|
* @param props Optional rotation, scale, origin, or quad.
|
|
@@ -151,61 +159,81 @@ export declare class Graphics {
|
|
|
151
159
|
draw(handle: ImageHandle, position: Vector2, props?: DrawProps): void;
|
|
152
160
|
/**
|
|
153
161
|
* Loads an image from a path.
|
|
154
|
-
* Unlike
|
|
155
|
-
|
|
162
|
+
* Unlike fetch, this pretends to be synchronous.
|
|
163
|
+
|
|
156
164
|
* @param path Image file path.
|
|
157
165
|
* @returns ImageHandle for use with draw.
|
|
158
166
|
*/
|
|
159
167
|
newImage(path: string): ImageHandle;
|
|
160
|
-
/**
|
|
161
|
-
* Sets the clipping region.
|
|
162
|
-
* @param this.ctx Canvas context.
|
|
163
|
-
* @param rect Clipping rectangle, or full canvas if omitted.
|
|
164
|
-
*/
|
|
165
|
-
clip(rect?: Rectangle): void;
|
|
166
168
|
/**
|
|
167
169
|
* Draws a polygon.
|
|
168
|
-
|
|
170
|
+
|
|
169
171
|
* @param mode Fill or line.
|
|
170
172
|
* @param color Fill or stroke color.
|
|
171
173
|
* @param points Array of [x, y] vertices.
|
|
172
|
-
* @param props Optional stroke properties.
|
|
174
|
+
* @param props Optional stroke and transform properties.
|
|
173
175
|
*/
|
|
174
|
-
polygon(mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
176
|
+
polygon(mode: DrawMode, color: Color, position: Vector2, points: Vector2[], props?: ShapeProps): void;
|
|
175
177
|
/**
|
|
176
178
|
* Draws individual pixels.
|
|
177
|
-
|
|
179
|
+
|
|
178
180
|
* @param color Fill color.
|
|
179
181
|
* @param pts Array of [x, y] positions.
|
|
180
182
|
*/
|
|
181
|
-
points(color: Color, pts: Vector2[]): void;
|
|
183
|
+
points(color: Color, pts: Vector2[], props?: TransformProps): void;
|
|
184
|
+
private applyTransform;
|
|
182
185
|
/**
|
|
183
186
|
* Saves canvas state.
|
|
184
|
-
|
|
187
|
+
|
|
185
188
|
*/
|
|
186
189
|
push(): void;
|
|
187
190
|
/**
|
|
188
191
|
* Restores canvas state.
|
|
189
|
-
|
|
192
|
+
|
|
190
193
|
*/
|
|
191
194
|
pop(): void;
|
|
192
195
|
/**
|
|
193
196
|
* Applies a translation.
|
|
194
|
-
|
|
197
|
+
|
|
195
198
|
* @param offset [x, y] offset.
|
|
196
199
|
*/
|
|
197
200
|
translate(offset: Vector2): void;
|
|
198
201
|
/**
|
|
199
202
|
* Applies a rotation.
|
|
200
|
-
|
|
203
|
+
|
|
201
204
|
* @param angle Rotation in radians.
|
|
202
205
|
*/
|
|
203
206
|
rotate(angle: number): void;
|
|
204
207
|
/**
|
|
205
208
|
* Applies a scale.
|
|
206
|
-
|
|
209
|
+
|
|
207
210
|
* @param factor Scale factor (number or [x, y]).
|
|
208
211
|
*/
|
|
209
212
|
scale(factor: number | Vector2): void;
|
|
213
|
+
/**
|
|
214
|
+
* The idiomatic way to render to an external canvas.
|
|
215
|
+
*
|
|
216
|
+
* Within this scope, the target canvas has changed.
|
|
217
|
+
*
|
|
218
|
+
* Outside, it stays the same.
|
|
219
|
+
*
|
|
220
|
+
* @param canvas The canvas to draw to.
|
|
221
|
+
* @param callback Functions that will be called while drawing to the target.
|
|
222
|
+
*/
|
|
223
|
+
withRenderTarget(context: CanvasRenderingContext2D, callback: () => void): void;
|
|
224
|
+
/**
|
|
225
|
+
* _For Expressive Purposes_
|
|
226
|
+
*
|
|
227
|
+
* A simple wrapper around push/pop (save/restore)
|
|
228
|
+
* that clearly allows a set of statements to have their
|
|
229
|
+
* own transform matrix.
|
|
230
|
+
*
|
|
231
|
+
* In other words, any `scale`, `translate`, etc.
|
|
232
|
+
* performed in this block does not affect the
|
|
233
|
+
* outside world.
|
|
234
|
+
*
|
|
235
|
+
* @param callback the drawing logic.
|
|
236
|
+
*/
|
|
237
|
+
withTransform(callback: () => void): void;
|
|
210
238
|
}
|
|
211
239
|
//# sourceMappingURL=graphics.d.ts.map
|