add docs for loadSprite
This commit is contained in:
parent
ed608eaac2
commit
99703e03d7
@ -308,31 +308,52 @@ lib.startGameLoop(function () {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### `drawSprite`
|
### `loadSprite`
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
lib.drawSprite(x: number, y: number, width: number, height: number, name: string) -> void
|
lib.loadSprite(name: string, width: number, height: number) -> Promise<Sprite>
|
||||||
```
|
```
|
||||||
|
|
||||||
Draws a sprite imported in the asset editor.
|
Loads a sprite from the asset editor with a specified width and height.
|
||||||
|
|
||||||
/* todo: link to sprite editor docs */
|
The `name` parameter is the file name as it is shown in the asset editor.
|
||||||
|
|
||||||
|
Setting the `width` and `height` to anything other than those of the original image will cause the sprite to be resized take up that size.
|
||||||
|
|
||||||
|
The loading is asynchronous, so you will have to add `await` for it to work.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
const mySprite = await lib.loadSprite("sprite.png", 50, 50);
|
||||||
|
```
|
||||||
|
|
||||||
|
After loading, the sprite is ready to be drawn.
|
||||||
|
|
||||||
|
See also: [`lib.drawSprite()`](#Lib-drawSprite)
|
||||||
|
|
||||||
|
### `drawSprite`
|
||||||
|
|
||||||
|
```ts
|
||||||
|
lib.drawSprite(x: number, y: number, sprite: Sprite) -> void
|
||||||
|
```
|
||||||
|
|
||||||
|
Draws a loaded sprite at the specified coordinates.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cloudSprite = await loadSprite("cloud.png", 20, 10);
|
||||||
|
|
||||||
lib.startGameLoop(function () {
|
lib.startGameLoop(function () {
|
||||||
lib.clear("blue");
|
lib.clear("blue");
|
||||||
lib.drawSprite(20, 30, 20, 10, "cloud.png");
|
lib.drawSprite(20, 30, cloudSprite);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: Sprite images have to be loaded. This is done asynchronously, meaning a sprite might not
|
Before drawing, the sprite must be loaded into a variable.
|
||||||
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
|
See also: [`lib.loadSprite()`](#Lib-loadSprite)
|
||||||
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`
|
### `drawSpriteRotated`
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user