doc rotate and stuff

This commit is contained in:
sfja 2025-10-15 00:34:54 +02:00
parent 935f99c22d
commit 2b87a57d43

View File

@ -197,6 +197,22 @@ Registers a gameloop function, that is called on every tick.
See also: [`Models.LoopFunc`](#Models-LoopFunc)
### `width`
```ts
lib.width -> number;
```
Get canvas width in pixels.
### `height`
```ts
lib.width -> number;
```
Get canvas height in pixels.
### `isPressed`
```ts
@ -311,6 +327,22 @@ lib.startGameLoop(function () {
});
```
Note: Sprite images have to be loaded. This is done asynchronously, meaning a sprite might not appear on the canvas after the first call to `drawSprite`.
Note: The sprite images are cached internally on it's `name`, `width` and `height` property. If these are values are different between calls, new sprite images will be loaded. This means that after a resize, the sprite may not appear immediately.
### `drawSpriteRotated`
```ts
lib.drawSpriteRotated(x: number, y: number, width: number, height: number, name: string, angle: number) -> void
```
Same as `drawSprite`, but the sprite is rotate according to the `angle` parameter, specified in radians (meaning a full rotation is `2 * Math.PI`.) The sprite is rotated around the **center**.
Note: Angles have a granularity/precision of 360 steps per rotation. This is becuse sprite images are cached internally on `angle` in addition to `name`, `width` and `height`.
See also [`drawSprite`](#Lib-drawSprite).
### `drawRect`
```ts
@ -335,6 +367,45 @@ lib.startGameLoop(function () {
});
```
### `drawLine`
```ts
lib.drawLine(x0: number, y0: number, x1: number, y1: number, thickness: number, color: string) -> void
```
Draws a line.
### `drawPath`
```ts
lib.drawPath(path: [number, number][], color: string) -> void
```
Fills an arbitrary polygon with [`Color`](#Models-Color).
Example:
```ts
lib.drawPath([
[0, 0],
[10, 0],
[10, 10],
[0, 10],
], "blue");
```
Note: The `path` array must contain at minimum 1 element.
### `drawPathLine`
```ts
lib.drawPathLine(path: [number, number][], thickness: number, color: string) -> void
```
Draws the outline of an arbitrary polygon.
See also [`drawPath`](#Lib-drawPath).
### `onMouseMove`
```ts