zerk.game.engine.viewport Class
Viewport
This class is responsible for rendering the world on a canvas.
Item Index
Methods
- _clearMessages
- _debugDrawGrid
- _getCanvasX
- _getCanvasY
- _getEntitiesInViewport
- _log
- _renderBody
- _renderBodyAngleIndicator
- _renderDebugInfo
- _renderDebugInfoLine
- _renderEntity
- _renderEntityBoundingBody
- _renderEntityOriginIndicator
- _renderFixture
- _renderFixtureBoundingCircle
- _renderFixtureBoundingPolygon
- _renderFixtureBoundingShape
- _renderFixtureBoundingShape
- _renderMessages
- _renderSprite
- _renderText
- _renderViewCenterIndicator
- _renderWorldCenterIndicator
- _setupRequestAnimationFrame
- _setViewPosition
- autoScale
- clear
- clearMessages
- fromScaleX
- fromScaleY
- getHeight
- getOffsetX
- getOffsetY
- getWidth
- getX
- getY
- init
- registerMessage
- render
- reset
- setX
- setY
- start
- stop
- toScaleX
- toScaleY
- unregisterMessage
- zoomIn
- zoomOut
Methods
_clearMessages
()
protected
Removes messages that timed out
_debugDrawGrid
()
protected
Renders the grid
_getCanvasX
-
meter
-
pixel
Parameters:
-
meter
Float -
pixel
Integer
Returns:
_getCanvasY
-
meter
-
pixel
Parameters:
-
meter
Float -
pixel
Integer
Returns:
_getEntitiesInViewport
()
Array
protected
Returns a list of all entities currently visible in the viewport
Returns:
_log
-
msg
Local log method
Parameters:
-
msg
StringLog message
_renderBody
-
entity
-
body
Renders a body onto the game canvas
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
_renderBodyAngleIndicator
-
entity
-
body
Renders an angle indicator for each body of the entity
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
_renderDebugInfo
()
protected
Renders debug information onto the game canvas
_renderDebugInfoLine
-
text
-
line
Renders a line of debug information onto the game canvas
Parameters:
-
text
StringText to be rendered
-
line
IntegerRow number
_renderEntity
-
entity
Renders an entity onto the game canvas
Parameters:
-
entity
zerk.game.engine.entityEntity
_renderEntityBoundingBody
-
entity
-
body
Renders a bounding box for a body
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
_renderEntityOriginIndicator
-
entity
Renders the entity origin indicator
Parameters:
-
entity
zerk.game.engine.entityEntity
_renderFixture
-
entity
-
body
-
fixture
Renders a fixture onto the body buffer canvas
Parameters:
-
entity
zerk.engine.entity.entityEntity
-
body
zerk.engine.physics.body.bodyBody
-
fixture
zerk.engine.physics.fixture.fixtureFixture
_renderFixtureBoundingCircle
-
entity
-
body
-
fixture
Renders the bounding area for a circle shaped fixture
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
-
fixture
zerk.game.engine.physics.fixtureFixture
_renderFixtureBoundingPolygon
-
entity
-
body
-
fixture
Renders the bounding area for a polygon shaped fixture
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
-
fixture
zerk.game.engine.physics.fixtureFixture
_renderFixtureBoundingShape
-
entity
-
body
-
fixture
Renders a shape indicating the bounding area of a fixture
Delegate method for the fixture bounding shape methods
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
-
fixture
zerk.game.engine.physics.fixtureFixture
_renderFixtureBoundingShape
-
entity
-
body
-
fixture
Renders the bounding area for a box shaped fixture
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.physics.bodyBody
-
fixture
zerk.game.engine.physics.fixtureFixture
_renderMessages
()
protected
Renders messages
_renderSprite
-
entity
-
body
-
fixture
-
sprite
Render sprite
Parameters:
-
entity
zerk.game.engine.entity -
body
zerk.game.engine.physics.body -
fixture
zerk.game.engine.physics.fixture -
sprite
zerk.game.engine.viewport.sprite
_renderText
-
text
-
x
-
y
-
font
-
size
-
color
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
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
Un-scales given value by current zoom factor
Parameters:
-
value
FloatValue
Returns:
fromScaleY
-
value
Un-scales given value by current zoom factor
Parameters:
-
value
FloatValue
Returns:
getHeight
()
Returns the height of the viewport in pixels
Returns:
getOffsetX
()
Returns the horizontal view position in meters
Returns:
getOffsetY
()
Returns the vertical view position in meters
Returns:
getWidth
()
Returns the width of the viewport in pixels
Returns:
getX
()
Returns the horizontal view position in pixels
Returns:
getY
()
Returns the vertical view position in pixels
Returns:
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:
setY
()
Sets the vertical view position in pixels
Returns:
start
()
Start the viewport
stop
()
Stop the viewport
toScaleX
-
value
Scales given value by current zoom factor
Parameters:
-
value
FloatValue
Returns:
toScaleY
-
value
Scales given value by current zoom factor
Parameters:
-
value
FloatValue
Returns:
unregisterMessage
-
id
Unregisters a message
Parameters:
-
id
StringMessage 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