Skip to content

Commit 266d7f6

Browse files
committed
document. Closes DRE-794. Closes DRE-996.
1 parent 873ebd3 commit 266d7f6

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

combined-ingredients.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,44 @@ if (hit) {
15251525
}
15261526
```
15271527

1528+
## Drawing with Pixi
1529+
```ts
1530+
import { Behavior, RawPixi } from "@dreamlab/engine";
1531+
import * as PIXI from "@dreamlab/vendor/pixi.ts";
1532+
1533+
export default class GraphicsDemo extends Behavior {
1534+
rawPixi!: RawPixi;
1535+
g!: PIXI.Graphics;
1536+
1537+
onInitialize() {
1538+
if (!this.game.isClient()) return;
1539+
this.rawPixi = this.game.local.spawn({
1540+
type: RawPixi,
1541+
name: "GraphicsTest",
1542+
transform: { position: this.entity.pos, z: 5 },
1543+
});
1544+
1545+
// Create a PIXI.Graphics and add it to the RawPixi container
1546+
this.g = new PIXI.Graphics();
1547+
this.rawPixi!.container!.addChild(this.g);
1548+
1549+
// 3) Draw something simple
1550+
this.g
1551+
.rect(0, 0, 5, 5)
1552+
.fill("#00ffb7");
1553+
}
1554+
1555+
onPostTick() {
1556+
if (!this.game.isClient()) return;
1557+
// Keep your graphics positioned relative to your entity
1558+
this.rawPixi.globalTransform.position.x = this.entity.pos.x;
1559+
this.rawPixi.globalTransform.position.y = this.entity.pos.y;
1560+
}
1561+
}
1562+
```
1563+
1564+
You can also attach it to a RawPixi entity itself.
1565+
15281566
---
15291567

15301568

docs/guide/preloading.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Preloading Assets
2+
3+
4+
Textures, sounds, and other assets can be preloaded by defining a `preload.ts` file in the root of your project
5+
6+
```ts
7+
export default definePreload({
8+
textures: ["res://assets/a.png"],
9+
// ... sounds, etc
10+
custom: async () => {
11+
// custom preloading goes here
12+
}
13+
});
14+
```

0 commit comments

Comments
 (0)