API Docs for: 0.1.0
Show:

zerk.game.engine.viewport Class

Viewport

This class is responsible for rendering the world on a canvas.

Methods

_clearMessages

() protected

Removes messages that timed out

_debugDrawGrid

() protected

Renders the grid

_getCanvasX

(
  • meter
  • pixel
)
Integer protected

Parameters:

  • meter Float
  • pixel Integer

Returns:

Integer:

_getCanvasY

(
  • meter
  • pixel
)
Integer protected

Parameters:

  • meter Float
  • pixel Integer

Returns:

Integer:

_getEntitiesInViewport

() Array protected

Returns a list of all entities currently visible in the viewport

Returns:

Array: Entity list

_log

(
  • msg
)
protected

Local log method

Parameters:

  • msg String

    Log message

_renderBody

(
  • entity
  • body
)
protected

Renders a body onto the game canvas

Parameters:

_renderBodyAngleIndicator

(
  • entity
  • body
)
protected

Renders an angle indicator for each body of the entity

Parameters:

_renderDebugInfo

() protected

Renders debug information onto the game canvas

_renderDebugInfoLine

(
  • text
  • line
)
protected

Renders a line of debug information onto the game canvas

Parameters:

  • text String

    Text to be rendered

  • line Integer

    Row number

_renderEntity

(
  • entity
)
protected

Renders an entity onto the game canvas

Parameters:

_renderEntityBoundingBody

(
  • entity
  • body
)
protected

Renders a bounding box for a body

Parameters:

_renderEntityOriginIndicator

(
  • entity
)
protected

Renders the entity origin indicator

Parameters:

_renderFixture

(
  • entity
  • body
  • fixture
)
protected

Renders a fixture onto the body buffer canvas

Parameters:

  • entity zerk.engine.entity.entity

    Entity

  • body zerk.engine.physics.body.body

    Body

  • fixture zerk.engine.physics.fixture.fixture

    Fixture

_renderFixtureBoundingCircle

(
  • entity
  • body
  • fixture
)
protected

Renders the bounding area for a circle shaped fixture

Parameters:

_renderFixtureBoundingPolygon

(
  • entity
  • body
  • fixture
)
protected

Renders the bounding area for a polygon shaped fixture

Parameters:

_renderFixtureBoundingShape

(
  • entity
  • body
  • fixture
)
protected

Renders a shape indicating the bounding area of a fixture

Delegate method for the fixture bounding shape methods

Parameters:

_renderFixtureBoundingShape

(
  • entity
  • body
  • fixture
)
protected

Renders the bounding area for a box shaped fixture

Parameters:

_renderMessages

() protected

Renders messages

_renderSprite

(
  • entity
  • body
  • fixture
  • sprite
)
protected

Render sprite

Parameters:

_renderText

(
  • text
  • x
  • y
  • font
  • size
  • color
)
protected

Render text onto the game canvas

Parameters:

  • text String
  • x Integer
  • y Integer
  • font String
  • size Integer
  • color String

_renderViewCenterIndicator

() protected

Renders the view center indicator

_renderWorldCenterIndicator

() protected

Renders the world center indicator

_setupRequestAnimationFrame

() protected

Crossbrowser requestAnimationFrame

http://paulirish.com/2011/requestanimationframe-for-smart-animating/

http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

requestAnimationFrame polyfill by Erik Möller

fixes from Paul Irish and Tino Zijdel

_setViewPosition

(
  • x
  • y
)
protected

Set the view position to a given world position

Parameters:

  • x Float
  • y Float

autoScale

()

Scale the viewport size to the game canvas size

clear

()

Clear the viewport

clearMessages

()

Removes all messages

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

getHeight

()

Returns the height of the viewport in pixels

Returns:

Integer

getOffsetX

()

Returns the horizontal view position in meters

Returns:

Float

getOffsetY

()

Returns the vertical view position in meters

Returns:

Float

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

init

(
  • engine
)

Class constructor

Parameters:

registerMessage

(
  • message
)

Registers a message

Parameters:

render

()

Renders the current world state onto the game canvas

reset

()

Reset the viewport

setX

()

Sets the horizontal view position in pixels

Returns:

Float

setY

()

Sets the vertical view position in pixels

Returns:

Float

start

()

Start the viewport

stop

()

Stop the viewport

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

unregisterMessage

(
  • id
)

Unregisters a message

Parameters:

  • id String

    Message id

zoomIn

()

Increases current zoom factor by factor 10

zoomOut

()

Decreases current zoom factor by factor 10

Properties

_bufferBody

DOMElement protected

Buffer to render full bodies

_bufferBodyContext

Object protected

Context of the body buffer

_bufferFixture

DOMElement protected

Buffer for rendering of single fixtures

_bufferFixtureContext

Object protected

Context of the fixture buffer

_canvas

DOMElement protected

Game canvas

_context

Object protected

Context of the main canvas

_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

_messages

Array protected

Text messages

_offsetX

Float protected

Horizontal view position in meters

_offsetY

Float protected

Vertical view position in meters

_running

Boolean protected

Inidcates if the viewport is running

_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

_zoom

Float protected

Zoom factor