Options
All
  • Public
  • Public/Protected
  • All
Menu

react-super-tilemap

Index

Type Aliases

CameraContext: { cameraMotionQueue: MotionRequest<TilePosition | "center">[]; cameraPosition?: TilePosition; currentCameraMotion?: CurrentMotion<TilePosition>; currentZoomMotion?: CurrentMotion<number>; zoom: number; zoomMotionQueue: MotionRequest<number>[]; addCameraMotion: any; addZoomMotion: any }

The context of the ThirdPersonCamera component.

Type declaration

CurrentMotion<T>: { easing?: EasingType; endAt: number; initialPosition: T; startAt: number; targetPosition: T }

A motion that is being executed.

Type Parameters

Type declaration

  • Optional easing?: EasingType

    The easing function to use for the motion.

    Easing functions specify the rate of change of a parameter over time

    default

    'linear'

  • endAt: number

    The time at which the motion will end in long milliseconds.

  • initialPosition: T

    The initial position before the motion.

  • startAt: number

    The time at which the motion started in long milliseconds.

  • targetPosition: T

    The target position after the motion.

CurrentMotionPosition: number | TilePosition
EasingType: "linear" | "easeInQuad" | "easeOutQuad" | "easeInOutQuad" | "easeInCubic" | "easeOutCubic" | "easeInOutCubic" | "easeInQuart" | "easeOutQuart" | "easeInOutQuart" | "easeInQuint" | "easeOutQuint" | "easeInOutQuint" | "easeInSine" | "easeOutSine" | "easeInOutSine" | "easeInExpo" | "easeOutExpo" | "easeInOutExpo" | "easeInCirc" | "easeOutCirc" | "easeInOutCirc" | "easeInElastic" | "easeOutElastic" | "easeInOutElastic" | "easeInBack" | "easeOutBack" | "easeInOutBack" | "easeInBounce" | "easeOutBounce" | "easeInOutBounce"

Supported easing types

EventBusChannel<T>: { emit: any; off: any; on: any }

Type Parameters

Type declaration

  • emit:function
    • emit<Key>(key: Key, ...payload: Parameters<T[Key]>): void
    • Type Parameters

      • Key extends string | number | symbol

      Parameters

      • key: Key
      • Rest ...payload: Parameters<T[Key]>

      Returns void

  • off:function
    • off<Key>(key: Key, handler: T[Key]): void
  • on:function
    • on<Key>(key: Key, handler: T[Key]): (() => void)
    • Type Parameters

      • Key extends string | number | symbol

      Parameters

      • key: Key
      • handler: T[Key]

      Returns (() => void)

        • (): void
        • Returns void

EventHandler<T>: ((payload: T) => void)

Type Parameters

  • T = any

Type declaration

    • (payload: T): void
    • Parameters

      • payload: T

      Returns void

EventKey: string | symbol
EventMap: Record<EventKey, EventHandler>
ManualCameraProps: ManualCameraSettings & { children?: ReactNode }
ManualCameraSettings: { clickable?: boolean; position?: TilePosition; zoom?: number }

Type declaration

  • Optional clickable?: boolean

    Flag that indicates if the tiles are clickable

  • Optional position?: TilePosition

    Camera position

  • Optional zoom?: number

    Camera zoom

ManualElementProps: ManualElementSettings & { children?: ReactNode }
ManualElementSettings: { elementKey: string; layer: number; spriteKey: string; tilePosition: TilePosition }

Type declaration

  • elementKey: string

    Unique key to identify the element.

  • layer: number

    In witch layer order the element should be rendered.

  • spriteKey: string

    The key of the sprite to use for the element.

  • tilePosition: TilePosition

    The position of the element in the tilemap.

MapDimensions: { cols: number; rows: number }

Map dimensions (number of cols and rows)

Type declaration

  • cols: number
  • rows: number
MotionRequest<T>: { settings: MotionSettings; target: T }

A motion request.

Type Parameters

Type declaration

  • settings: MotionSettings

    Settings of the motion.

    example

    { speed: 100, easing: 'linear' }

  • target: T

    The target position after the motion.

MotionRequestTarget: TilePosition | "center" | number
MotionSettings: { easing?: EasingType; maxDuration?: number; minDuration?: number; speed: number }

Motion settings.

Type declaration

  • Optional easing?: EasingType

    The easing function to use for the motion.

    Easing functions specify the rate of change of a parameter over time

    default

    'linear'

    see

    https://easings.net/

  • Optional maxDuration?: number

    The maximum duration of the motion in seconds. If it is not provided, the motion will run until it reaches the target using the configured speed. If it is provided, the speed will be calculated to reach the target in the given max duration.

  • Optional minDuration?: number

    The minimum duration of the motion in seconds.

    default

    0

  • speed: number

    The speed of the motion in pixels per second.

MotionableElementEvents: { onMotionComplete?: any }

Type declaration

MotionableElementProps: MotionableElementSettings & MotionableElementEvents & { children?: ReactNode }
MotionableElementSettings: ManualElementSettings & { motionSettings: MotionSettings; spriteKeyEastMotion?: string; spriteKeyNorthMotion?: string; spriteKeySouthMotion?: string; spriteKeyWestMotion?: string }
Position: { x: number; y: number }

Absolute position (x, y)

Type declaration

  • x: number
  • y: number
RecenterCameraMotion: { settings: MotionSettings; target: RecenterCameraMotionTarget }

Configuration for camera motions that are being executed after a canvas resize or zoom change.

Type declaration

  • settings: MotionSettings

    Settings of the motion.

  • target: RecenterCameraMotionTarget

    The target position of the camera after any canvas resize. If it is 'center', the camera will be centered on the tilemap. If it is a tile position, the camera will be centered on the given tile position.

RecenterCameraMotionTarget: "center" | TilePosition

Types of recenter motion targets.

Size: { height: number; width: number }

Size (width and height)

Type declaration

  • height: number

    Height value

  • width: number

    Width value

SpriteDefinition: { animationDelay?: number; imagesSrc: string[]; key: string; offset?: TilePosition; size?: Size }

Definition of a sprite to be used in the tilemap.

The sprite is defined by a list of images that will be used as frames.

The first image will be used as the default image.

The rest of the images will be used for animation.

If there is only one image, the animation will be disabled.

The images must have the same size.

example

const spriteDefinition = { key: "my-sprite", imagesSrc: [ "https://example.com/image1.png", "https://example.com/image2.png", "https://example.com/image3.png", ], animationDelay: 1000, tileSize: { width: 1, height: 1 }, };

Type declaration

  • Optional animationDelay?: number

    Delay in milliseconds between each animation frame.

    If not provided, the default value will be used.

    If there is only one image, the animation will be disabled.

    The delay must be greater than 0.

    default

    1000

  • imagesSrc: string[]

    List of image sources to be used as sprite frames.

    The first image will be used as the default image.

    The rest of the images will be used for animation.

    If there is only one image, the animation will be disabled The images must have the same size.

    example

    imagesSrc: [ "https://example.com/image1.png", "https://example.com/image2.png", "https://example.com/image3.png", ],

  • key: string

    Unique key to identify the sprite.

  • Optional offset?: TilePosition

    Sprite's offset in tiles. Indicates how many tiles the sprite will be offset from it origin.

    default

    { col: 0, row: 0 }

  • Optional size?: Size

    Sprite's size in tiles. Indicates how many tiles the sprite will occupy.

    If not provided, the default value will be used.

    The size width and height must be greater than 0.

    default

    { width: 1, height: 1 }

ThirdPersonCameraEvents: { onCameraMotionEnd?: any; onZoomMotionEnd?: any }

Type declaration

ThirdPersonCameraProps: ThirdPersonCameraSettings & ThirdPersonCameraEvents & { children?: ReactNode }
ThirdPersonCameraSettings: { dragSensitivity?: number; draggable?: boolean; initialCameraPosition?: TilePosition | "center"; initialZoom?: number; recenterCameraOnResize?: RecenterCameraMotion; recenterCameraOnZoom?: RecenterCameraMotion; zoomIncrement?: number; zoomeable?: boolean }

Type declaration

  • Optional dragSensitivity?: number

    Tilemap's drag speed sensitivity.

    If not provided, the default value will be used. If provided, it must be greater than 0.

    default

    1

  • Optional draggable?: boolean

    Flag to indicate if the tilemap drag controls to move the camera are enabled.

    default

    true

  • Optional initialCameraPosition?: TilePosition | "center"

    Initial camera position when the tilemap is mounted.

    If not provided, the default value will be used.

    default

    'center'

  • Optional initialZoom?: number

    Initial zoom level when the tilemap is mounted.

    If not provided, the default value will be used.

    default

    0

  • Optional recenterCameraOnResize?: RecenterCameraMotion

    Configuration for camera motions that are being executed when the canvas is resized.

  • Optional recenterCameraOnZoom?: RecenterCameraMotion

    Configuration for camera motions that are being executed after a the zoom level is changed.

  • Optional zoomIncrement?: number

    Zoom increment per wheel scroll.

    If not provided, the default value will be used.

    default

    1

  • Optional zoomeable?: boolean

    Flag to indicate if the tilemap zoom control is enabled.

    default

    true

TilePosition: { col: number; row: number }

Position of a tile in the grid (col, row)

Type declaration

  • col: number
  • row: number
TilemapElement: { layer: number; spriteKey: string; tilePosition: TilePosition }

A tilemap element.

Type declaration

  • layer: number

    In witch layer order the element should be rendered.

  • spriteKey: string

    The key of the sprite to use for the element.

  • tilePosition: TilePosition

    The position of the element in the tilemap.

TilemapElementMap: Record<string, TilemapElement>

A map of tilemap elements.

TilemapEventChannel: { onClick: any; onContextMenu: any; onDoubleClick: any; onMouseDown: any; onMouseMove: any; onMouseUp: any; onWheel: any }

Type declaration

TilemapEvents: { onSpritesLoadError?: any; onTileClick?: any; onTileContextMenu?: any; onTileDoubleClick?: any; onTileHover?: any; onTileHoverOut?: any; onTilemapClick?: any; onTilemapContextMenu?: any; onTilemapDoubleClick?: any }

Tilemap events.

Type declaration

TilemapProps: TilemapSettings & TilemapEvents & { children?: ReactNode }

Tilemap component props.

TilemapSettings: { backgroundColor?: string; defaultTileSize?: number; spriteDefinition?: SpriteDefinition[]; tilmapScheme?: string[][][] }

Tilemap settings.

Type declaration

  • Optional backgroundColor?: string

    Tilemap's background color.

    If not provided, the default value will be used. If provided, it must be a valid CSS color.

    example

    backgroundColor: "#000000" backgroundColor: "rgb(0, 0, 0)" backgroundColor: "rgba(0, 0, 0, 0.5)"

    default

    '#cbf0ff'

  • Optional defaultTileSize?: number

    Tile default tile size in px.

    If not provided, the default value will be used. If provided, it must be greater than 0.

    default

    16

  • Optional spriteDefinition?: SpriteDefinition[]

    Definition of the sprites that tilemap will render.

  • Optional tilmapScheme?: string[][][]

    Scheme of Columns/rows/layers of sprite keys that will be rendered on the tile map.

Variables

ManualCamera: FunctionComponent<ManualCameraSettings> = ...

This component is used to manually control the camera position and zoom of the tilemap.

Use clickable prop to enable or disable click controls.

param props

ManualCameraProps

ManualElement: FunctionComponent<ManualElementProps> = ...
MotionableElement: FunctionComponent<MotionableElementProps> = ...
ThirdPersonCamera: FunctionComponent<ThirdPersonCameraProps> = ...

Use this component to operate with a third person camera in the tilemap.

Here you can forget about control the camera position and zoom because this component will do it for you enabling drag and zoom controls by default.

This component will provide a context to all its children. There you can use the useThirdPersonCamera hook to get this context and use it to control the camera using the addCameraMotion and addZoomMotion functions.

param props

component props

Tilemap: FunctionComponent<TilemapProps> = ...

Tilemap main component.

param props
tilemapEventChannel: EventBusChannel<TilemapEventChannel> = ...

Functions

Generated using TypeDoc