> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Graphics2DLibrary

> Built-in 2D graphics library powered by [Konva](https://konvajs.org/).

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:24](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L24)

Built-in 2D graphics library powered by [Konva](https://konvajs.org/).

## Remarks

Creates a Konva `Stage` and a default `Layer` during `__init`. Game code
interacts with `Context.graphics.stage`/`.baseLayer` directly to add
shapes, images, and animations, in game coordinates (the design resolution
of `Context.viewport`). The stage follows every viewport change (window
resize, fullscreen, monitor switch, fit mode change): it is resized,
scaled, offset and letterboxed/cropped according to the viewport's fit. Client-only — `__init`
throws if `InitContext.container` is missing.

## Extends

* `Library`

## Constructors

### Constructor

> **new Graphics2DLibrary**(`relationships?`): `Graphics2DLibrary`

Defined in: packages/common/dist/index.d.ts:510

#### Parameters

##### relationships?

`Partial`\<`LibraryRelationships`>

Optional ordering overrides, keyed by other
libraries' `key`.

#### Returns

`Graphics2DLibrary`

#### Inherited from

`Library.constructor`

## Properties

### key

> `readonly` **key**: `"graphics"`

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:25](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L25)

This library's identity: its slot on `Context`, its registry key, and
the identifier used to reference it in ordering relationships.

#### Overrides

`Library.key`

## Accessors

### baseLayer

#### Get Signature

> **get** **baseLayer**(): `Layer`

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:63](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L63)

##### Returns

`Layer`

***

### relationships

#### Get Signature

> **get** **relationships**(): `LibraryRelationships`

Defined in: packages/common/dist/index.d.ts:512

**`Internal`**

##### Returns

`LibraryRelationships`

#### Inherited from

`Library.relationships`

***

### stage

#### Get Signature

> **get** **stage**(): `Stage`

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:58](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L58)

##### Returns

`Stage`

## Methods

### \_\_clear()

> **\_\_clear**(): `Promise`\<`void`>

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:51](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L51)

Called once after the tick loop stops.

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__clear`

***

### \_\_events()

> **\_\_events**(`_ctx`): `Promise`\<`void`>

Defined in: packages/common/dist/index.d.ts:521

Called every tick, in run order, whether or not the tick loop is
paused — unlike `__run`. Use this for event/message draining that must
not be affected by pause (e.g. listening for the command that resumes
the loop), not for gameplay simulation.

#### Parameters

##### \_ctx

[`Context`](https://docs.nanoforge.eu/references/engine/3.0.0/ecs/index/interfaces/Context)

#### Returns

`Promise`\<`void`>

#### Inherited from

`Library.__events`

***

### \_\_init()

> **\_\_init**(`ctx`): `Promise`\<`void`>

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:31](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L31)

Called once, in dependency order, before the tick loop starts.

#### Parameters

##### ctx

`InitContext`

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__init`

***

### \_\_run()

> **\_\_run**(`_ctx`): `Promise`\<`void`>

Defined in: packages/common/dist/index.d.ts:523

Called every tick, in run order, while the tick loop is active and not paused.

#### Parameters

##### \_ctx

[`Context`](https://docs.nanoforge.eu/references/engine/3.0.0/ecs/index/interfaces/Context)

#### Returns

`Promise`\<`void`>

#### Inherited from

`Library.__run`

***

### expose()

> **expose**(): [`GraphicsContextApi`](https://docs.nanoforge.eu/references/engine/3.0.0/graphics-2d/interfaces/GraphicsContextApi)

Defined in: [modules/graphics-2d/src/graphics-2d.library.ts:68](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/graphics-2d/src/graphics-2d.library.ts#L68)

Returns this library's public contribution to `Context[this.key]`.

#### Returns

[`GraphicsContextApi`](https://docs.nanoforge.eu/references/engine/3.0.0/graphics-2d/interfaces/GraphicsContextApi)

#### Remarks

Return a plain object exposing only what game code should be able to
reach — never `this` — so internal state and lifecycle hooks never leak
onto `Context`. Libraries with nothing to expose (headless libraries)
can leave this unimplemented; they simply won't appear on `Context`.

#### Overrides

`Library.expose`

***

### throwNotInitializedError()

> `protected` **throwNotInitializedError**(): `never`

Defined in: packages/common/dist/index.d.ts:536

#### Returns

`never`

#### Inherited from

`Library.throwNotInitializedError`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.