Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Core

Defines the core engine used to render scenes (aka GameScreens). A project that use the zepr.ts framework must define exactly one instance of Core or derived classes

Hierarchy

Index

Constructors

constructor

  • Defines a core Engine. 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 Core

Properties

Private _height

_height: number

Scene height

Private _width

_width: number

Scene width

Private background

background: HTMLImageElement | HTMLCanvasElement

Current background

Private backgroundColor

backgroundColor: string

Alternative background color if no image background is set

Private backgroundPosition

backgroundPosition: Point

Background position

Private backgroundType

backgroundType: BackgroundType

How background image should be displayed

Private cache

cache: Map<string, any>

Object cache

Private canvas

canvas: HTMLCanvasElement

Main canvas

Protected coords

coords: Rectangle

Private ctx

ctx: CanvasRenderingContext2D

Main Canvas rendering context

Private horizontalOverflow

horizontalOverflow: boolean

If overflow is horizontal

Private initLoader

initLoader: boolean

If loader is initialised

Private lastTime

lastTime: number

Last render time

Private loaderScreen

loaderScreen: LoaderScreen

Loader screen

Private modifiedSpriteList

modifiedSpriteList: boolean

Check for modification of Sprites list in current frame

Private nextScreen

nextScreen: GameScreen

Next screen

Private offCanvas

offCanvas: HTMLCanvasElement

Canvas used for off-screen rendering (double buffering)

Private offCtx

offCtx: CanvasRenderingContext2D

off-screen Canvas rendering context

Private overflow

overflow: boolean

Screen overflow

Private overflowCenter

overflowCenter: Point

Screen overflow center

Private resourcesLoader

resourcesLoader: ResourcesLoader

Resources loader

Private scale

scale: number

Scene scale in user view

Protected screen

screen: GameScreen

Current screen

Protected spriteList

spriteList: Array<Sprite<any>>

Sprites defined in current screen

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

  • Caches a new GameScreen instance

    Parameters

    • name: string

      Key associated to the screen

    • newScreen: GameScreen

      New screen to reference

    Returns Core

    current engine core (to chain screen definitions)

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)

forceHierarchyUpdate

  • forceHierarchyUpdate(): void
  • Forces update of sprites hierarchy. Should be used when index of sprites is updated.

    Returns void

getData

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

    Parameters

    • key: string

      id of the object to load

    Returns any

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

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
  • Resets screen settings. Internally used for screen switch

    Returns 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
  • Main loop

    • Redraws main frame
    • Executes current GameScreen run method
    • Renders sprites for next frame

    Parameters

    • time: number

      Delai d'appel

    Returns 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
  • Changes overflow state

    Parameters

    • _overflow: boolean

      New overflow state

    Returns void

start

Generated using TypeDoc