Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Engine

Defines the engine used to render scenes (aka GameScreens) with support for mouse and touch events.

Hierarchy

Index

Constructors

constructor

  • Defines a Engine with mouse/touch management. The scene is always maximized and centered on screen with preservation of its aspect ratio (Adds borders when needed)

    Parameters

    • width: number

      Scene width

    • height: number

      Scene height

    • Optional loader: LoaderScreen

      Optional custom screen loader

    Returns Engine

Properties

Protected coords

coords: Rectangle

Private endDrag

endDrag: boolean = false

Whether drag is complete

Private eventMap

eventMap: Map<string, function>

Functions used to manage events

Private isTouchZoom

isTouchZoom: boolean

Is touch currently used to zoom

Private maxZoom

maxZoom: number

Maximum zoom value

Private minZoom

minZoom: number

Minimum zoom value

Private mouseEnabled

mouseEnabled: boolean

Mouse control enabled

Private mouseEventType

mouseEventType: MouseEventType

Mouse control enabled with sprites

Private mouseMoveEnabled

mouseMoveEnabled: boolean

Mouse movement control enabled

Private mouseMovement

mouseMovement: Vector

Current mouse movement

Private mousePrevious

mousePrevious: Point

Previous position

Protected screen

screen: GameScreen

Current screen

Protected spriteList

spriteList: Array<Sprite<any>>

Sprites defined in current screen

Private touchZoomState

touchZoomState: State

Current touch zoom state

Private zoomEnabled

zoomEnabled: boolean

Zoom (scroll / touch)

Private zoomState

zoomState: State

Current zoom state

Static DEFAULT_BACKGROUND_COLOR

DEFAULT_BACKGROUND_COLOR: "#000000" = "#000000"

Default background color used when nothing is specified for a Screen

Static ZOOM_RATIO

ZOOM_RATIO: number = 1.1

Zoom ratio used for mouse scroll wheel

Accessors

height

  • get height(): number

width

  • get width(): number

Methods

Protected addImage

  • addImage(url: string): HTMLImageElement
  • Loads an image, adds it to the cache (If not already done)

    Parameters

    • url: string

      Absolute or relative path to the image

    Returns HTMLImageElement

    An image or null if not found

addScreen

addSprite

  • addSprite(sprite: Sprite<any>): boolean
  • Adds sprite to screen. A sprite is inserted only once in a Screen

    Parameters

    • sprite: Sprite<any>

      Sprite to add

    Returns boolean

    true if the Sprite is added (false if already present)

disableMouseControl

  • disableMouseControl(): void

disableMouseDrag

  • disableMouseDrag(): void

disableZoomControl

  • disableZoomControl(): void
  • Disables mouse wheel and touch pinch events.

    Returns void

enableMouseControl

  • Enables mouse and touch click events. Current Screen must implement ClickListener interface

    Parameters

    • Default value eventType: MouseEventType | boolean = MouseEventType.BASIC

      How mouse events should be managed

    Returns void

enableMouseDrag

  • enableMouseDrag(): void
  • Enables mouse and touch drag events. Current Screen must implement DragListener interface.

    Returns void

enableZoomControl

  • enableZoomControl(minZoom?: number, maxZoom?: number): void
  • Enables mouse wheel and touch pinch events. Current Screen must implement ZoomListener interface.

    Parameters

    • Default value minZoom: number = 0.1
    • Default value maxZoom: number = 10

    Returns void

forceHierarchyUpdate

  • forceHierarchyUpdate(): void

getData

  • getData(key: string): any
  • Loads object from cache

    Parameters

    • key: string

      id of the object to load

    Returns any

Private getEventPosition

  • getEventPosition(event: MouseEvent | TouchEvent): Point
  • Converts screen coords of event to Screen coords

    Parameters

    • event: MouseEvent | TouchEvent

      Source event

    Returns Point

    The screen coordinates of the event

getImage

  • getImage(url: string): HTMLImageElement
  • Loads an image. Equivalent to addImage

    Parameters

    • url: string

      Absolute or relative path to the image

    Returns HTMLImageElement

    An image or null if not found

Protected onDown

  • onDown(event: MouseEvent | TouchEvent): void
  • Listens mouse down events to manage both click and drag events

    Parameters

    • event: MouseEvent | TouchEvent

      Source event

    Returns void

Protected onEndZoom

  • onEndZoom(event: TouchEvent): void
  • Reset state when zoom touch ends

    Parameters

    • event: TouchEvent

      Source event

    Returns void

Protected onMove

  • onMove(event: MouseEvent | TouchEvent): void
  • Listens move events to manage drag events

    Parameters

    • event: MouseEvent | TouchEvent

      Source event

    Returns void

Protected onUp

  • onUp(event: MouseEvent | TouchEvent): boolean
  • Listens mouse up events to manage both click and drag events

    Parameters

    • event: MouseEvent | TouchEvent

      Source event

    Returns boolean

Protected onZoom

  • onZoom(event: WheelEvent | TouchEvent): void
  • Listens zoom events

    Parameters

    • event: WheelEvent | TouchEvent

      Source event

    Returns void

removeSprite

  • removeSprite(sprite: Sprite<any>): boolean
  • Removes instance of sprite

    Parameters

    • sprite: Sprite<any>

      Sprite to remove

    Returns boolean

    true if the sprite is really removed (false if not present)

Protected repaint

  • repaint(): void
  • Refreshes scene. Renders background and sprites on offest canvas

    Returns void

Protected reset

  • reset(): void

Protected resize

  • resize(event?: UIEvent): void
  • Adapts view to a new screen size

    Parameters

    • Optional event: UIEvent

      Resize event

    Returns void

Protected run

  • run(time: number): void

setBackground

  • setBackground(bgImage: HTMLImageElement | HTMLCanvasElement | string, backgroundType?: number): void
  • Defines current background image. The image is not distorted to fit the screen.

    Parameters

    • bgImage: HTMLImageElement | HTMLCanvasElement | string

      The new background image. May be either an image, its relative or absolute url or a canvas

    • Default value backgroundType: number = BackgroundType.TOP_LEFT

      How background should be displayed

    Returns void

setBackgroundColor

  • setBackgroundColor(color: string): void
  • Defines current background color. Has no effect if a background image is already defined for the current screen. See also setBackground.

    Parameters

    • color: string

      The new background color

    Returns void

setCenter

  • setCenter(position: Point): void
  • Centers scene. This setting has no effect if there's no overflow

    Parameters

    • position: Point

      New centered position. Use null to set center in the middle of the scene

    Returns void

setData

  • setData(key: string, value: any): void
  • Stores object to cache

    Parameters

    • key: string

      id of the object to store

    • value: any

      object to store

    Returns void

setOverflow

  • setOverflow(_overflow: boolean): void

setZoom

  • setZoom(newZoom: number): void
  • Defines new zoom value. Ignored without enableZoomControl

    Parameters

    • newZoom: number

      New zoom value, within the minZoom - maxZoom limits

    Returns void

start

Generated using TypeDoc