@latticexyz/phaserx

# @latticexyz/phaserx

# Table of contents

# Enumerations

# Classes

# Interfaces

# Type Aliases

  • Asset
  • Camera
  • Coord
  • Key
  • TileAnimation

# Variables

  • GameObjectClasses
  • ZERO_VECTOR

# Functions

  • addCoords
  • chunkCoordToTileCoord
  • chunkToPixelCoord
  • coordEq
  • cornerTileCoordsFromRegionCoords
  • createAnimatedTilemap
  • createCamera
  • createChunkedTilemap
  • createChunks
  • createCulling
  • createDebugger
  • createInput
  • createObjectPool
  • createPhaserEngine
  • createVirtualTilemap
  • defineAssetsConfig
  • defineCameraConfig
  • defineMapConfig
  • definePhaserConfig
  • defineScaleConfig
  • defineScene
  • defineSceneConfig
  • generateFrames
  • getChunksInArea
  • getObjectsInArea
  • isRectangle
  • isSprite
  • isTileInArea
  • load
  • mod
  • pixelCoordToTileCoord
  • pixelToChunkCoord
  • removeAllTweens
  • tileCoordToChunkCoord
  • tileCoordToPixelCoord
  • tween

# Type Aliases

# Asset

Ƭ Asset: { key: string ; path: string ; type: Image } | { key: string ; options: { frameHeight: number ; frameWidth: number } ; path: string ; type: SpriteSheet } | { key: string ; options: { imagePath: string } ; path: string ; type: MultiAtlas }

# Defined in

packages/phaserx/src/types.ts:176


# Camera

Ƭ Camera: Object

# Type declaration

Name Type
centerOn (x: number, y: number) => void
centerOnCoord (tileCoord: Coord, tileWidth: number, tileHeight: number) => void
dispose () => void
ignore (objectPool: ObjectPool, ignore: boolean) => void
phaserCamera Phaser.Cameras.Scene2D.Camera
setScroll (x: number, y: number) => void
setZoom (zoom: number) => void
worldView$ Observable<Phaser.Cameras.Scene2D.Camera["worldView"]>
zoom$ Observable<number>

# Defined in

packages/phaserx/src/types.ts:13


# Coord

Ƭ Coord: Object

# Type declaration

Name Type
x number
y number

# Defined in

packages/phaserx/src/types.ts:54


# Key

Ƭ Key: keyof typeof Phaser.Input.Keyboard.KeyCodes | "POINTER_LEFT" | "POINTER_RIGHT"

# Defined in

packages/phaserx/src/createInput.ts:18


# TileAnimation

Ƭ TileAnimation<TileKeys>: TileKeys[]

# Type parameters

Name Type
TileKeys extends number

# Defined in

packages/phaserx/src/tilemap/types.ts:28

# Variables

# GameObjectClasses

Const GameObjectClasses: Object

# Type declaration

Name Type
Line typeof Line
Rectangle typeof Rectangle
Sprite typeof Sprite
Text typeof Text

# Defined in

packages/phaserx/src/constants.ts:7


# ZERO_VECTOR

Const ZERO_VECTOR: Coord

# Defined in

packages/phaserx/src/utils/coords.ts:3

# Functions

# addCoords

addCoords(a, b): Object

# Parameters

Name Type
a Coord
b Coord

# Returns

Object

Name Type
x number
y number

# Defined in

packages/phaserx/src/utils/coords.ts:34


# chunkCoordToTileCoord

chunkCoordToTileCoord(chunkCoord, tileWidth, tileHeight, chunkSize): WorldCoord

# Parameters

Name Type
chunkCoord Coord
tileWidth number
tileHeight number
chunkSize number

# Returns

WorldCoord

# Defined in

packages/phaserx/src/utils/coords.ts:73


# chunkToPixelCoord

chunkToPixelCoord(chunkCoord, chunkSize): PixelCoord

# Parameters

Name Type
chunkCoord Coord
chunkSize number

# Returns

PixelCoord

# Defined in

packages/phaserx/src/utils/coords.ts:45


# coordEq

coordEq(a?, b?): boolean

# Parameters

Name Type
a? Coord
b? Coord

# Returns

boolean

# Defined in

packages/phaserx/src/utils/coords.ts:28


# cornerTileCoordsFromRegionCoords

cornerTileCoordsFromRegionCoords(regionCoords, regionLength): Coord[]

# Parameters

Name Type
regionCoords Coord[]
regionLength number

# Returns

Coord[]

# Defined in

packages/phaserx/src/utils/coords.ts:5


# createAnimatedTilemap

createAnimatedTilemap<TileKeys, LayerKeys, AnimationKeys>(config): AnimatedTilemap<TileKeys, LayerKeys, AnimationKeys>

# Type parameters

Name Type
TileKeys extends number
LayerKeys extends string
AnimationKeys extends string

# Parameters

Name Type
config Omit<ChunkedTilemapConfig<TileKeys, string>, "tiles"> & { animationInterval: number }

# Returns

AnimatedTilemap<TileKeys, LayerKeys, AnimationKeys>

# Defined in

packages/phaserx/src/tilemap/createAnimatedTilemap.ts:9


# createCamera

createCamera(phaserCamera, options): Camera

# Parameters

Name Type
phaserCamera Camera
options CameraConfig

# Returns

Camera

# Defined in

packages/phaserx/src/createCamera.ts:6


# createChunkedTilemap

createChunkedTilemap<TileKeys, LayerKeys>(params): ChunkedTilemap<TileKeys, LayerKeys>

# Type parameters

Name Type
TileKeys extends number
LayerKeys extends string

# Parameters

Name Type
params ChunkedTilemapConfig<TileKeys, LayerKeys>

# Returns

ChunkedTilemap<TileKeys, LayerKeys>

# Defined in

packages/phaserx/src/tilemap/createChunkedTilemap.ts:22


# createChunks

createChunks(worldView$, chunkSize, padding?): Object

# Parameters

Name Type Default value
worldView$ Observable<Area> undefined
chunkSize number undefined
padding number 100

# Returns

Object

Name Type
addedChunks$ Observable<Coord>
chunkSize number
removedChunks$ Observable<Coord>
visibleChunks { current: CoordMap<boolean> }
visibleChunks.current CoordMap<boolean>

# Defined in

packages/phaserx/src/createChunks.ts:6


# createCulling

createCulling(objectPool, camera, chunks): Object

# Parameters

Name Type Default value
objectPool Object undefined
objectPool.get <Type>(entity: string | number, type: Type) => ObjectPoolReturnType<typeof type> undefined
objectPool.groups Object undefined
objectPool.groups.Line Group Phaser.GameObjects.Line
objectPool.groups.Rectangle Group Phaser.GameObjects.Rectangle
objectPool.groups.Sprite Group Phaser.GameObjects.Sprite
objectPool.groups.Text Group Phaser.GameObjects.Text
objectPool.ignoreCamera (cameraId: number, ignore: boolean) => void undefined
objectPool.objects ObservableMap<string, EmbodiedEntity<"Sprite" | "Rectangle" | "Line" | "Text">> undefined
objectPool.remove (entity: string | number) => void undefined
camera Camera undefined
chunks Object undefined
chunks.addedChunks$ Observable<Coord> undefined
chunks.chunkSize number undefined
chunks.removedChunks$ Observable<Coord> undefined
chunks.visibleChunks Object undefined
chunks.visibleChunks.current CoordMap<boolean> undefined

# Returns

Object

Name Type
dispose () => void

# Defined in

packages/phaserx/src/createCulling.ts:45


# createDebugger

createDebugger(camera, chunks, scene, objectPool, map): void

# Parameters

Name Type Default value
camera Camera undefined
chunks Object undefined
chunks.addedChunks$ Observable<Coord> undefined
chunks.chunkSize number undefined
chunks.removedChunks$ Observable<Coord> undefined
chunks.visibleChunks Object undefined
chunks.visibleChunks.current CoordMap<boolean> undefined
scene Scene undefined
objectPool Object undefined
objectPool.get <Type>(entity: string | number, type: Type) => ObjectPoolReturnType<typeof type> undefined
objectPool.groups Object undefined
objectPool.groups.Line Group Phaser.GameObjects.Line
objectPool.groups.Rectangle Group Phaser.GameObjects.Rectangle
objectPool.groups.Sprite Group Phaser.GameObjects.Sprite
objectPool.groups.Text Group Phaser.GameObjects.Text
objectPool.ignoreCamera (cameraId: number, ignore: boolean) => void undefined
objectPool.objects ObservableMap<string, EmbodiedEntity<"Sprite" | "Rectangle" | "Line" | "Text">> undefined
objectPool.remove (entity: string | number) => void undefined
map AnimatedTilemap<number, string, string> undefined

# Returns

void

# Defined in

packages/phaserx/src/createDebugger.ts:13


# createInput

createInput(inputPlugin): Object

# Parameters

Name Type
inputPlugin InputPlugin

# Returns

Object

Name Type
click$ Observable<Pointer>
disableInput () => void
dispose () => void
doubleClick$ Observable<Pointer>
drag$ Observable<undefined | Area>
enableInput () => void
enabled { current: boolean = true }
enabled.current boolean
keyboard$ Observable<Key>
onKeyPress (keySelector: (pressedKeys: Set<Key>) => boolean, callback: () => void) => void
pointerdown$ Observable<{ event: MouseEvent ; pointer: Pointer }>
pointermove$ Observable<{ pointer: Pointer = inputPlugin.manager.activePointer }>
pointerup$ Observable<{ event: MouseEvent ; pointer: Pointer }>
pressedKeys ObservableSet<Key>
rightClick$ Observable<Pointer>
setCursor (cursor: string) => void

# Defined in

packages/phaserx/src/createInput.ts:20


# createObjectPool

createObjectPool(scene): Object

# Parameters

Name Type
scene Scene

# Returns

Object

Name Type
get <Type>(entity: string | number, type: Type) => ObjectPoolReturnType<typeof type>
groups { Line: Group = Phaser.GameObjects.Line; Rectangle: Group = Phaser.GameObjects.Rectangle; Sprite: Group = Phaser.GameObjects.Sprite; Text: Group = Phaser.GameObjects.Text }
groups.Line Group
groups.Rectangle Group
groups.Sprite Group
groups.Text Group
ignoreCamera (cameraId: number, ignore: boolean) => void
objects ObservableMap<string, EmbodiedEntity<"Sprite" | "Rectangle" | "Line" | "Text">>
remove (entity: string | number) => void

# Defined in

packages/phaserx/src/createObjectPool.ts:15


# createPhaserEngine

createPhaserEngine<S>(options): Promise<{ dispose: () => void ; game: Game ; scenes: Scenes<S> }>

# Type parameters

Name Type
S extends ScenesConfig

# Parameters

Name Type
options PhaserEngineConfig<S>

# Returns

Promise<{ dispose: () => void ; game: Game ; scenes: Scenes<S> }>

# Defined in

packages/phaserx/src/createPhaserEngine.ts:15


# createVirtualTilemap

createVirtualTilemap<TileKeys, LayerKeys>(config): VirtualTilemap<TileKeys, LayerKeys>

# Type parameters

Name Type
TileKeys extends number
LayerKeys extends string

# Parameters

Name Type
config Omit<ChunkedTilemapConfig<TileKeys, LayerKeys>, "tiles">

# Returns

VirtualTilemap<TileKeys, LayerKeys>

# Defined in

packages/phaserx/src/tilemap/createVirtualTilemap.ts:7


# defineAssetsConfig

defineAssetsConfig<A>(assets): A

# Type parameters

Name Type
A extends Assets

# Parameters

Name Type
assets A

# Returns

A

# Defined in

packages/phaserx/src/guards.ts:17


# defineCameraConfig

defineCameraConfig(config): CameraConfig

# Parameters

Name Type
config CameraConfig

# Returns

CameraConfig

# Defined in

packages/phaserx/src/guards.ts:41


# defineMapConfig

defineMapConfig<A, T, L>(config): MapConfig<A, T, L>

# Type parameters

Name Type
A extends Assets
T extends TilesetConfig<A>
L extends LayerConfig<A, T>

# Parameters

Name Type
config MapConfig<A, T, L>

# Returns

MapConfig<A, T, L>

# Defined in

packages/phaserx/src/guards.ts:21


# definePhaserConfig

definePhaserConfig(options): Phaser.Types.Core.GameConfig

# Parameters

Name Type
options Object
options.scale undefined | ScaleConfig
options.scenes typeof GameScene[]

# Returns

Phaser.Types.Core.GameConfig

# Defined in

packages/phaserx/src/definePhaserConfig.ts:3


# defineScaleConfig

defineScaleConfig(config): ScaleConfig

# Parameters

Name Type
config ScaleConfig

# Returns

ScaleConfig

# Defined in

packages/phaserx/src/guards.ts:37


# defineScene

defineScene(options): typeof GameScene

# Parameters

Name Type
options Object
options.create? (scene: Scene) => void
options.key string
options.preload? (scene: Scene) => void
options.update? (scene: Scene) => void

# Returns

typeof GameScene

# Defined in

packages/phaserx/src/defineScene.ts:3


# defineSceneConfig

defineSceneConfig<A, S, T, M, Ans>(config): SceneConfig<A, S, T, M, Ans>

# Type parameters

Name Type
A extends Assets
S extends Object
T extends TilesetConfig<A>
M extends MapsConfig<A, T>
Ans extends Animation<A>[]

# Parameters

Name Type
config SceneConfig<A, S, T, M, Ans>

# Returns

SceneConfig<A, S, T, M, Ans>

# Defined in

packages/phaserx/src/guards.ts:27


# generateFrames

generateFrames<A>(anims, animation): Phaser.Types.Animations.AnimationFrame[]

# Type parameters

Name Type
A extends Assets

# Parameters

Name Type
anims AnimationManager
animation Animation<A>

# Returns

Phaser.Types.Animations.AnimationFrame[]

# Defined in

packages/phaserx/src/utils/generateFrames.ts:3


# getChunksInArea

getChunksInArea(area, chunkSize): CoordMap<boolean>

# Parameters

Name Type
area Area
chunkSize number

# Returns

CoordMap<boolean>

# Defined in

packages/phaserx/src/utils/chunks.ts:5


# getObjectsInArea

getObjectsInArea(groups, area): any[]

# Parameters

Name Type
groups Group[]
area Rectangle

# Returns

any[]

# Defined in

packages/phaserx/src/utils/area.ts:2


# isRectangle

isRectangle(gameObject, type): gameObject is Rectangle

# Parameters

Name Type
gameObject GameObject
type "Sprite" | "Rectangle" | "Line" | "Text"

# Returns

gameObject is Rectangle

# Defined in

packages/phaserx/src/guards.ts:52


# isSprite

isSprite(gameObject, type): gameObject is Sprite

# Parameters

Name Type
gameObject GameObject
type "Sprite" | "Rectangle" | "Line" | "Text"

# Returns

gameObject is Sprite

# Defined in

packages/phaserx/src/guards.ts:45


# isTileInArea

isTileInArea(tileCoord, area): boolean

# Parameters

Name Type
tileCoord Coord
area Area

# Returns

boolean

# Defined in

packages/phaserx/src/utils/coords.ts:19


# load

load(scene, callback): Promise<void>

# Parameters

Name Type
scene Scene
callback (loader: LoaderPlugin) => void

# Returns

Promise<void>

# Defined in

packages/phaserx/src/utils/load.ts:3


# mod

mod(a, b): number

# Parameters

Name Type
a number
b number

# Returns

number

# Defined in

packages/phaserx/src/utils/math.ts:1


# pixelCoordToTileCoord

pixelCoordToTileCoord(pixelCoord, tileWidth, tileHeight): WorldCoord

# Parameters

Name Type
pixelCoord Coord
tileWidth number
tileHeight number

# Returns

WorldCoord

# Defined in

packages/phaserx/src/utils/coords.ts:49


# pixelToChunkCoord

pixelToChunkCoord(pixelCoord, chunkSize): ChunkCoord

# Parameters

Name Type
pixelCoord Coord
chunkSize number

# Returns

ChunkCoord

# Defined in

packages/phaserx/src/utils/coords.ts:41


# removeAllTweens

removeAllTweens(gameObject): void

# Parameters

Name Type
gameObject GameObject

# Returns

void

# Defined in

packages/phaserx/src/utils/tween.ts:33


# tileCoordToChunkCoord

tileCoordToChunkCoord(tileCoord, tileWidth, tileHeight, chunkSize): ChunkCoord

# Parameters

Name Type
tileCoord Coord
tileWidth number
tileHeight number
chunkSize number

# Returns

ChunkCoord

# Defined in

packages/phaserx/src/utils/coords.ts:63


# tileCoordToPixelCoord

tileCoordToPixelCoord(tileCoord, tileWidth, tileHeight): PixelCoord

# Parameters

Name Type
tileCoord Coord
tileWidth number
tileHeight number

# Returns

PixelCoord

# Defined in

packages/phaserx/src/utils/coords.ts:56


# tween

tween(config, options?): Promise<void>

Add a tween to the provided game object.

# Parameters

Name Type
config TweenBuilderConfig
options? Object
options.keepExistingTweens? boolean

# Returns

Promise<void>

Promise that resolves when the tween is done.

# Defined in

packages/phaserx/src/utils/tween.ts:12