API Docs for: 0.1.0
Show:

zerk.game.engine.system.viewport.canvas Class

Canvas Viewport System

Visualization implementation for HTML Canvas.

Methods

_createCanvas

(
  • id
  • width
  • height
  • visible
)
DOMElement protected

Creates a canvas DOM element

Parameters:

  • id String

    DOM id

  • width Integer

    Canvas width

  • height Integer

    Canvas height

  • visible Boolean

    Canvas visibility

Returns:

DOMElement: Canvas DOM element

_debugDrawGrid

() protected

Renders the grid

_getCanvas

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME deprecated protected async

PROTECTEDMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

_getCanvasX

(
  • meter
  • pixel
)
Integer protected

Parameters:

  • meter Float
  • pixel Integer

Returns:

Integer:

_getCanvasY

(
  • meter
  • pixel
)
Integer protected

Parameters:

  • meter Float
  • pixel Integer

Returns:

Integer:

_getConfigDefaults

() Object protected

Returns the configuration defaults of the system

Returns:

Object: Default configuration

_getContext

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME deprecated protected async

PROTECTEDMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

_getEntitiesInViewport

() Array protected

Returns a list of all entities currently visible in the viewport

Returns:

Array: Entity list

_getSystem

(
  • name
)
zerk.game.engine.system protected

Returns system by given name

This method is used to communicate with other systems.

Parameters:

  • name String

    System name

Returns:

zerk.game.engine.system: System instance

_log

(
  • message
  • severity
)
protected

Local log method

Parameters:

  • message String

    Log message

  • severity Integer

    Log severity

_renderWorldCenterIndicator

() protected

Renders the world center indicator

_setViewPosition

(
  • x
  • y
)
protected

Set the view position to a given world position

Parameters:

  • x Float
  • y Float

addEntity

(
  • entity
)

Adds an entity to the system

Parameters:

bufferClear

(
  • buffer
)

Clear a buffer by given buffer id

Parameters:

  • buffer String

    Buffer id

bufferFlush

(
  • source
  • target
  • width
  • height
  • x
  • y
)

Flush a buffers content onto another buffer

Parameters:

  • source String

    Source buffer id

  • target String

    Target buffer id

  • width Float

    Target width

  • height Float

    Target height

  • x Float

    Target horizontal position

  • y Float

    Target vertical position

bufferInit

(
  • buffer
  • width
  • height
  • x
  • y
  • angle
)

Initializes a buffer for drawing

Parameters:

  • buffer String

    Buffer id

  • width Float

    Width

  • height Float

    Height

  • x Float

    Center x

  • y Float

    Center y

  • angle Float

    Angle

createBuffers

(
  • buffers
)
deprecated

Creates multiple buffers

Parameters:

  • buffers Object

    A list of buffers to be created

drawArc

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

PUBLICMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

drawLines

(
  • buffer
  • lines
  • color
  • lineWidth
)

Draw lines

Parameters:

  • buffer String

    Buffer id

  • lines Object

    Two dimensional array containing the lines

  • color String

    RGB color

  • lineWidth Float

    Width of the lines

drawPolygon

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

PUBLICMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

drawRect

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

Draw a rectangle

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAM_DESCRIPTION

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

drawText

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

PUBLICMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

fillArc

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

PUBLICMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

fillPolygon

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

PUBLICMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

fillRect

(
  • PARAM_NAME
)
Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

PUBLICMETHODDESCRIPTION

Parameters:

  • PARAM_NAME Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME

    PARAMDESCRIPTION SECONDLINE

Returns:

Boolean | Integer | Float | String | Object | Array | Function | Mixed | Any | CLASS_NAME: RETURN_DESCRIPTION

fireEvent

(
  • event
)
Boolen

Fire event

Parameters:

  • event String

    Event name

Returns:

Boolen: Returns false when the bubble was canceled

fromScaleX

(
  • value
)
Float

Un-scales given value by current zoom factor

Parameters:

  • value Float

    Value

Returns:

Float: Scaled value

fromScaleY

(
  • value
)
Float

Un-scales given value by current zoom factor

Parameters:

  • value Float

    Value

Returns:

Float: Scaled value

getBufferSize

(
  • buffer
)
Object

Returns the size of the buffer by given id

Parameters:

  • buffer String

    Buffer id

Returns:

Object: An object containing with and height

getCanvasElement

(
  • buffer
)
DOMElement

Return a canvas element for given buffer id

Parameters:

  • buffer String

    Buffer id

Returns:

DOMElement: Canvas element

getCanvasPhysicsDebug

() DOMElement

Returns the physics debug canvas DOM element

Returns:

DOMElement: Physics debug canvas DOM element

getCanvasPosition

(
  • buffer
)
Object

Returns a canvas position relative to its parent HTML document

Parameters:

  • buffer String

    Buffer id

Returns:

Object: An object containing x and y

getFPS

() Integer

Returns the current count of frames drawn per second

Returns:

Integer: FPS

getHeight

()

Returns the height of the viewport in pixels

Returns:

Integer

getName

() String

Returns the name of the system

Returns:

String: System name

getOffsetX

() deprecated

Returns the horizontal view position in meters

Returns:

Float

getOffsetY

() deprecated

Returns the vertical view position in meters

Returns:

Float

getPriority

() Integer

Returns the priority of the system

Returns:

Integer: System priority

getThread

() String

Returns the thread the systems runs in

Returns:

String: Thread name

getWidth

()

Returns the width of the viewport in pixels

Returns:

Integer

getX

()

Returns the horizontal view position in pixels

Returns:

Float

getY

()

Returns the vertical view position in pixels

Returns:

Float

getZoom

() Float

Return the current zoom factor

Returns:

Float: Zoom factor

init

(
  • engine
  • config
)

Class constructor

Parameters:

on

(
  • event
  • callback
  • scope
)

Register event handler

Parameters:

  • event String

    Event name

  • callback Function

    Callback function. Return false to cancel event bubble.

  • scope Object

    Scope to be used in callback function

removeEntity

(
  • entity
)

Removes an entity from the system

Parameters:

setX

()

Sets the horizontal view position in pixels

Returns:

Float

setY

()

Sets the vertical view position in pixels

Returns:

Float

start

()

Starts the system

stop

()

Stops the system

toScaleX

(
  • value
)
Float

Scales given value by current zoom factor

Parameters:

  • value Float

    Value

Returns:

Float: Scaled value

toScaleY

(
  • value
)
Float

Scales given value by current zoom factor

Parameters:

  • value Float

    Value

Returns:

Float: Scaled value

un

(
  • event
  • callback
)
Boolen

Unregister event handler

Parameters:

  • event String

    Event name

  • callback Function

    Callback function

Returns:

Boolen: Returns true on success

update

()

Updates the system

useComponent

(
  • name
)
Boolean

Returns true when the system is interested in given component

Parameters:

  • name String

    Component name

Returns:

Boolean: True when the system is intereseted in given component

zoomIn

()

Increases current zoom factor by factor 10

zoomOut

()

Decreases current zoom factor by factor 10

Properties

_canvas

Object protected

Register for canvas references

_config

Object protected

System configuration

_context

Object protected

Register for canvas context references

_engine

zerk.game.engine protected

Engine instance

Back reference to the engine instance.

_entities

Array protected

Entities register

Entities that this system is interested in.

_eventListeners

Array protected

List of event handlers

_fps

Integer protected

The number of rendered frames per second

_fpsCounter

Integer protected

Counter used to calculate FPS

_fpsSecond

Integer protected

Stores the second of the last FPS measuring

_frameCount

Integer protected

The total number of frames rendered

_height

Integer protected

Height of the viewport in pixels

_name

String protected

Name of the system

_offsetX

Float deprecated protected

Horizontal view position in meters

_offsetY

Float deprecated protected

Vertical view position in meters

_priority

Integer protected

Priority of this system

_thread

String protected

Thread that runs this system

_timer

DOMTimer protected

Rendering timer

_width

Integer protected

Width of the viewport in pixels

_x

Float protected

Horizontal view position in pixels

_y

Float protected

Vertical view position in pixels